:root {
  color-scheme: light;
  --blue: #1a73e8;
  --blue-deep: #185abc;
  --red: #ea4335;
  --yellow: #fbbc04;
  --green: #34a853;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --line-strong: #c9d3e1;
  --surface: #ffffff;
  --surface-soft: #f8fafd;
  --surface-blue: #e8f0fe;
  --shadow: 0 18px 42px rgba(60, 64, 67, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--ink);
  background: #eef3fb;
  font-family:
    "Inter",
    "Noto Sans JP",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
select,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(26, 115, 232, 0.24);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 980px);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface-soft);
  box-shadow: var(--shadow);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-lockup h1,
.brand-lockup p {
  margin: 0;
}

.brand-lockup h1 {
  font-size: 1.2rem;
  line-height: 1.2;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.25;
}

.product-mark {
  position: relative;
  width: 38px;
  height: 26px;
  flex: 0 0 auto;
  display: block;
}

.product-mark span {
  position: absolute;
  border-radius: 999px;
}

.product-mark span:nth-child(1) {
  width: 24px;
  height: 12px;
  left: 7px;
  top: 0;
  background: var(--blue);
}

.product-mark span:nth-child(2) {
  width: 14px;
  height: 20px;
  left: 0;
  top: 6px;
  background: var(--green);
}

.product-mark span:nth-child(3) {
  width: 16px;
  height: 18px;
  right: 0;
  top: 7px;
  background: var(--red);
}

.product-mark span:nth-child(4) {
  width: 28px;
  height: 10px;
  left: 5px;
  bottom: 0;
  background: var(--yellow);
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--blue-deep);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 800;
}

.icon-button:hover {
  border-color: var(--blue);
  background: var(--surface-blue);
}

.screen {
  min-height: 0;
  min-width: 0;
  display: none;
  overflow: hidden;
  padding: 16px 18px;
}

.screen.active {
  display: grid;
}

#homeScreen {
  grid-template-rows: auto auto auto;
  gap: 14px;
  align-content: start;
}

#practiceScreen {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

#termsScreen {
  min-height: 0;
}

.home-card,
.home-focus,
.controls-panel,
.quiz-panel,
.review-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.home-card {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.progress-zone {
  display: grid;
  gap: 10px;
}

.progress-copy {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.progress-copy span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.progress-copy strong {
  color: var(--blue-deep);
  font-size: 2.35rem;
  line-height: 0.95;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe6f5;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid div {
  min-width: 0;
  padding: 12px 8px;
  display: grid;
  justify-items: center;
  gap: 4px;
  border-radius: var(--radius);
  background: #f3f7ff;
  border: 1px solid #e0e8f6;
}

.stats-grid span {
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1;
  font-weight: 800;
}

.stats-grid small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.home-actions {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 800;
  line-height: 1.2;
}

.primary-button {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.primary-button:hover {
  background: var(--blue-deep);
  border-color: var(--blue-deep);
}

.secondary-button {
  color: var(--blue-deep);
  background: var(--surface);
  border-color: var(--line-strong);
}

.secondary-button:hover {
  background: var(--surface-blue);
  border-color: var(--blue);
}

.mastered-button {
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid #b7dfc2;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #137333;
  background: #e6f4ea;
  cursor: pointer;
  font-weight: 850;
  line-height: 1.2;
}

.mastered-button:hover {
  border-color: var(--green);
  background: #d8f0df;
}

.home-focus {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
}

.home-focus div {
  min-width: 0;
  padding: 14px 12px;
  display: grid;
  gap: 4px;
  border-right: 1px solid var(--line);
}

.home-focus div:last-child {
  border-right: 0;
}

.home-focus strong {
  font-size: 0.95rem;
  white-space: nowrap;
}

.home-focus span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.controls-panel {
  display: grid;
  grid-template-columns: minmax(150px, 0.85fr) minmax(260px, 1.15fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.control-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

select,
input[type="search"] {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

select {
  height: 36px;
}

select:focus,
input[type="search"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f6f9fe;
}

.segmented button {
  min-height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  color: var(--blue-deep);
  background: var(--surface-blue);
}

.mode-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.mode-dot.blue {
  background: var(--blue);
}

.mode-dot.yellow {
  background: var(--yellow);
}

.mode-dot.red {
  background: var(--red);
}

.quiz-panel {
  min-height: 0;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  overflow: hidden;
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.question-meta span {
  min-width: 0;
}

#questionCategory {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#questionIndex {
  flex: 0 0 auto;
}

#questionText {
  min-height: 0;
  max-height: 7.1rem;
  margin: 0;
  overflow: auto;
  color: var(--ink);
  font-size: 1.04rem;
  line-height: 1.36;
  font-weight: 850;
}

.answer-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
}

.options {
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(4, minmax(38px, auto));
  align-content: start;
  gap: 7px;
  overflow: hidden;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: #f7f9fc;
  text-align: center;
  padding: 18px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 1.1rem;
}

.empty-state span {
  line-height: 1.5;
}

.option-button {
  min-width: 0;
  min-height: 38px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 6px 10px 6px 7px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font-weight: 800;
}

.option-button:hover:not(:disabled) {
  border-color: var(--blue);
  background: #f4f8ff;
}

.option-button:disabled {
  cursor: default;
  opacity: 1;
}

.option-key {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--blue-deep);
  background: var(--surface-blue);
  font-size: 0.9rem;
}

.option-label {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.option-button.correct {
  border-color: var(--green);
  background: #e6f4ea;
}

.option-button.correct .option-key {
  color: #137333;
  background: #ceead6;
}

.option-button.wrong {
  border-color: var(--red);
  background: #fce8e6;
}

.option-button.wrong .option-key {
  color: #a50e0e;
  background: #fad2cf;
}

.feedback {
  position: absolute;
  inset: 0;
  z-index: 2;
  min-height: 0;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 14px;
  color: var(--muted);
  background: rgba(247, 249, 252, 0.98);
  box-shadow: 0 12px 28px rgba(60, 64, 67, 0.18);
  font-size: 1.2rem;
  line-height: 1.55;
}

.feedback[hidden] {
  display: none;
}

.feedback p {
  margin: 8px 0 0;
}

.feedback ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.feedback-result {
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 850;
}

.feedback .explanation-heading {
  margin-top: 8px;
}

.feedback .explanation-heading strong {
  color: var(--ink);
  font-size: 1.2rem;
}

.feedback-correct {
  border-color: #b7dfc2;
  background: #e6f4ea;
}

.feedback-wrong {
  border-color: #f2b8b5;
  background: #fce8e6;
}

.actions-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(78px, 0.72fr) minmax(0, 1fr);
  gap: 8px;
}

.actions-panel .secondary-button,
.actions-panel .mastered-button,
.actions-panel .primary-button {
  width: 100%;
}

.review-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.review-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.review-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.review-header span {
  display: inline-block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.term-list {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.term-item {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.term-item.mastered {
  border-color: #b7dfc2;
  background: #f7fbf8;
}

.term-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.term-title-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
}

.mastered-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 850;
}

.mastered-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
}

.term-item.mastered .mastered-toggle {
  color: #137333;
  border-color: #b7dfc2;
  background: #e6f4ea;
}

.english-label {
  color: var(--blue-deep);
  font-size: 0.82rem;
  font-weight: 800;
}

.difficulty,
.pill {
  width: fit-content;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.difficulty.easy,
.difficulty-a {
  color: #137333;
  background: #e6f4ea;
}

.difficulty.medium,
.difficulty-b {
  color: #9a6700;
  background: #fff7db;
}

.difficulty.hard,
.difficulty-c {
  color: #a50e0e;
  background: #fce8e6;
}

.explanation-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.term-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.term-item details {
  color: var(--muted);
  font-size: 0.86rem;
}

.term-item summary {
  color: var(--blue-deep);
  cursor: pointer;
  font-weight: 800;
}

.term-item details div,
.term-item details p {
  margin-top: 7px;
}

.term-meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  color: var(--muted);
  background: #f1f3f4;
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav-button {
  min-width: 0;
  min-height: 52px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.nav-button span {
  font-size: 1.08rem;
  line-height: 1;
}

.nav-button strong {
  font-size: 0.72rem;
  line-height: 1;
}

.nav-button.active {
  color: var(--blue-deep);
  background: var(--surface-blue);
  border-color: #c7d8fb;
}

@media (max-width: 720px) {
  .app-shell {
    width: 100%;
    box-shadow: none;
  }

  .screen {
    padding: 12px;
  }

  .app-header {
    padding-right: 12px;
    padding-left: 12px;
  }

  .brand-lockup h1 {
    font-size: 1.04rem;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  .controls-panel {
    grid-template-columns: minmax(112px, 0.75fr) minmax(0, 1.25fr);
    gap: 6px;
    padding: 7px;
  }

  .segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .segmented button {
    min-width: 0;
    min-height: 34px;
    padding: 0 2px;
    gap: 3px;
    font-size: 0.72rem;
  }

  .mode-dot {
    width: 7px;
    height: 7px;
  }

  .quiz-panel {
    padding: 10px;
    gap: 7px;
  }

  #questionText {
    max-height: 7rem;
    font-size: 1.02rem;
    line-height: 1.36;
  }

  .option-button {
    min-height: 36px;
  }

  .option-key {
    width: 27px;
    height: 27px;
  }

  .feedback {
    padding: 14px;
    font-size: 1.2rem;
    line-height: 1.5;
  }

  .review-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .review-header input {
    width: 100%;
  }
}

@media (max-width: 430px) {
  #homeScreen {
    gap: 10px;
  }

  .home-card {
    padding: 14px;
    gap: 12px;
  }

  .progress-copy strong {
    font-size: 2rem;
  }

  .stats-grid {
    gap: 6px;
  }

  .stats-grid div {
    padding: 10px 5px;
  }

  .stats-grid span {
    font-size: 1.2rem;
  }

  .stats-grid small {
    font-size: 0.68rem;
  }

  .home-actions {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .home-actions .primary-button,
  .home-actions .secondary-button {
    min-height: 44px;
  }

  .home-focus {
    grid-template-columns: 1fr;
  }

  .home-focus div {
    grid-template-columns: 58px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .home-focus div:last-child {
    border-bottom: 0;
  }

  .option-button {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
    padding-right: 10px;
  }

  .option-key {
    width: 27px;
    height: 27px;
  }
}

@media (max-height: 700px) {
  .app-header {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: 9px;
  }

  .screen {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .home-card {
    padding: 12px;
    gap: 10px;
  }

  .progress-copy strong {
    font-size: 1.8rem;
  }

  .progress-track {
    height: 9px;
  }

  .stats-grid div {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .primary-button,
  .secondary-button,
  .mastered-button {
    min-height: 42px;
  }

  .home-focus div {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  #practiceScreen {
    gap: 8px;
  }

  .controls-panel {
    padding: 6px;
  }

  select {
    height: 34px;
  }

  input[type="search"] {
    height: 38px;
  }

  .segmented button {
    min-height: 34px;
  }

  .quiz-panel {
    padding: 8px;
    gap: 6px;
  }

  #questionText {
    max-height: 6.8rem;
    font-size: 1rem;
    line-height: 1.36;
  }

  .options {
    grid-template-rows: repeat(4, minmax(34px, auto));
    gap: 6px;
  }

  .option-button {
    min-height: 34px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .feedback {
    padding: 12px;
    font-size: 1.14rem;
    line-height: 1.48;
  }

  .bottom-nav {
    padding-top: 8px;
  }

  .nav-button {
    min-height: 46px;
  }
}
