html {
  font-size: 16px;
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100svh;
  margin: 0;
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
  color: #1f2a32;
  background:
    linear-gradient(90deg, rgba(246, 250, 248, 0.92), rgba(246, 250, 248, 0.68)),
    url("/assets/background/schoolroom_01.png") center / cover fixed;
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

button,
a,
input,
select {
  touch-action: manipulation;
}

button,
.btn,
.form-control,
.form-select {
  min-height: 44px;
}

.form-control,
.form-select {
  font-size: 1rem;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(42, 124, 255, 0.45);
  outline-offset: 3px;
}

.app-nav {
  position: sticky;
  top: 0;
  z-index: 1030;
  padding-top: env(safe-area-inset-top);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(31, 42, 50, 0.12);
  backdrop-filter: blur(10px);
}

.app-nav .navbar-toggler {
  width: 44px;
  min-height: 44px;
  border-color: rgba(31, 42, 50, 0.2);
}

.app-nav .navbar-toggler-icon {
  background-image:
    linear-gradient(#1f2a32, #1f2a32),
    linear-gradient(#1f2a32, #1f2a32),
    linear-gradient(#1f2a32, #1f2a32);
  background-repeat: no-repeat;
  background-position: center 7px, center 14px, center 21px;
  background-size: 24px 2px;
}

.app-nav .navbar-brand,
.app-nav .nav-link {
  color: #1f2a32;
  font-weight: 700;
}

.app-container {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 calc(32px + env(safe-area-inset-bottom));
}

.app-screen {
  min-height: calc(100svh - 120px);
  display: flex;
  align-items: center;
}

.ios-install-tip {
  width: min(720px, calc(100% - 24px));
  margin: 12px auto 0;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid rgba(55, 104, 74, 0.22);
  border-radius: 12px;
  background: rgba(244, 251, 246, 0.96);
  box-shadow: 0 10px 24px rgba(31, 42, 50, 0.09);
}

.ios-install-tip[hidden] {
  display: none;
}

.ios-install-tip div {
  display: grid;
  gap: 2px;
}

.ios-install-tip strong {
  color: #37684a;
}

.ios-install-tip span {
  color: #53636e;
  font-size: 0.92rem;
}

.ios-install-tip button {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid rgba(31, 42, 50, 0.18);
  border-radius: 8px;
  background: #fff;
  color: #1f2a32;
  font: inherit;
  font-weight: 800;
}

.question-screen {
  display: block;
}

.title-screen {
  justify-content: space-between;
  gap: 36px;
}

.screen-grid {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  align-items: center;
  gap: 32px;
}

.screen-copy,
.main-panel,
.settings-panel {
  width: 100%;
  min-width: 0;
}

.main-panel,
.settings-panel {
  padding: 28px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(31, 42, 50, 0.12);
}

.settings-panel {
  max-width: 760px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 8px;
  color: #37684a;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 7vw, 4.4rem);
  font-weight: 900;
  line-height: 1.08;
}

.main-panel h1,
.settings-panel h1,
.question-header h1 {
  font-size: 2rem;
}

.lead-text,
.helper-text {
  margin: 0 0 22px;
  color: #4a5963;
  font-size: 1.08rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 24px;
}

.learning-form {
  display: grid;
  gap: 22px;
}

.home-screen {
  align-items: start;
}

.home-screen .screen-grid {
  align-items: start;
}

.home-screen .main-panel {
  padding: 24px;
}

.home-side-panel {
  position: sticky;
  top: 88px;
  display: grid;
  gap: 16px;
  align-self: start;
}

.home-side-panel .character-image {
  max-height: 42vh;
}

.home-side-panel .dialogue-bubble,
.home-side-panel .conversation-card {
  width: min(100%, 360px);
}

.level-status-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 22px;
}

.compact-level-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.level-status-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  background: #fff;
}

.level-select-card {
  width: 100%;
  border-color: rgba(31, 42, 50, 0.12);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.level-select-card:not(:disabled):hover,
.level-select-card.active {
  border-color: #2e8b57;
  box-shadow: 0 8px 18px rgba(46, 139, 87, 0.14);
}

.level-select-card.active {
  background: #f4fbf6;
}

.level-select-card:disabled {
  cursor: not-allowed;
}

.level-status-item div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.level-status-item strong,
.level-status-item span,
.level-status-item small {
  overflow-wrap: anywhere;
}

.level-status-item strong {
  color: #37684a;
  font-weight: 900;
}

.level-status-item span,
.level-status-item small {
  color: #53636e;
  font-weight: 700;
}

.level-status-item small {
  flex: 0 0 auto;
  text-align: right;
}

.level-status-item.locked {
  background: #f3f7fa;
  opacity: 0.72;
}

.form-group {
  display: grid;
  gap: 8px;
}

.course-level-list {
  display: grid;
  gap: 20px;
}

.course-level-section {
  display: grid;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.course-level-section h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 900;
}

.course-level-section small {
  color: #53636e;
  font-weight: 700;
}

.course-unit-group {
  display: grid;
  gap: 10px;
}

.course-unit-heading {
  color: #37684a;
  font-size: 0.95rem;
  font-weight: 900;
}

.course-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.course-card {
  display: grid;
  gap: 10px;
  min-height: 124px;
  padding: 14px 16px;
  border: 2px solid rgba(65, 136, 96, 0.2);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.course-card-top,
.course-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.course-card strong,
.course-card small,
.course-card span {
  overflow-wrap: anywhere;
}

.course-card strong {
  color: #1f2a32;
  font-weight: 900;
}

.course-card small,
.course-card-meta span {
  color: #53636e;
  font-weight: 700;
}

.course-status-badge {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.course-status-badge.cleared {
  background: #dff4e8;
  color: #1f6a46;
}

.course-status-badge.pending {
  background: #eef3f7;
  color: #4e5e69;
}

.btn-check:checked + .course-card {
  border-color: #2a7cff;
  box-shadow: 0 10px 20px rgba(42, 124, 255, 0.16);
  transform: translateY(-1px);
}

.course-card.is-cleared {
  background: linear-gradient(180deg, #ffffff 0%, #f7fff9 100%);
}

.compact-learning-form {
  gap: 18px;
}

.course-picker-panel {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  border: 1px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.selected-course-summary {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 8px;
  background: #f4fbf6;
  border: 1px solid rgba(46, 139, 87, 0.2);
}

.selected-course-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.selected-course-title-row div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.selected-course-title-row span:first-child {
  color: #37684a;
  font-size: 0.9rem;
  font-weight: 900;
}

.selected-course-title-row h2 {
  margin: 0;
  color: #1f2a32;
  font-size: 1.2rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.selected-course-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selected-course-meta span {
  padding: 4px 9px;
  border-radius: 999px;
  background: #fff;
  color: #53636e;
  font-size: 0.9rem;
  font-weight: 800;
}

.selected-course-summary p {
  margin: 0;
  color: #53636e;
  font-weight: 700;
}

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

.study-mode-card {
  display: grid;
  gap: 4px;
  min-height: 78px;
  padding: 12px;
  border: 2px solid rgba(65, 136, 96, 0.2);
  border-radius: 8px;
  background: #fff;
  color: #1f2a32;
  text-align: center;
  cursor: pointer;
}

.study-mode-card strong,
.study-mode-card span {
  overflow-wrap: anywhere;
}

.study-mode-card strong {
  color: #37684a;
  font-weight: 900;
}

.study-mode-card span {
  color: #53636e;
  font-size: 0.9rem;
  font-weight: 800;
}

.btn-check:checked + .study-mode-card {
  border-color: #2e8b57;
  background: #f4fbf6;
  box-shadow: 0 8px 18px rgba(46, 139, 87, 0.14);
}

.compact-action-row {
  margin-top: 0;
}

.compact-action-row .btn-primary {
  min-width: 220px;
}

.form-group label,
.toggle-row strong {
  font-weight: 800;
}

.segmented-control {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.character-stage {
  display: grid;
  justify-items: center;
  gap: 16px;
}

.character-nameplate {
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(31, 42, 50, 0.12);
  color: #37684a;
  font-size: 0.9rem;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(31, 42, 50, 0.08);
}

.character-image {
  width: min(100%, 340px);
  max-height: 58vh;
  object-fit: contain;
  filter: drop-shadow(0 18px 22px rgba(31, 42, 50, 0.22));
}

.dialogue-bubble {
  width: min(100%, 360px);
  margin: 0;
  padding: 16px 18px;
  background: #fffdf4;
  border: 2px solid #e4c75b;
  border-radius: 8px;
  color: #2f3437;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(31, 42, 50, 0.12);
}

.conversation-card {
  display: grid;
  gap: 8px;
  margin: 0 0 22px;
  padding: 16px 18px;
  border-radius: 8px;
  background: #fffdf4;
  border: 1px solid #e4c75b;
  color: #2f3437;
}

.conversation-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.conversation-card-header span,
.conversation-card strong {
  font-weight: 900;
}

.conversation-card-header span {
  color: #37684a;
}

.conversation-card-header small,
.conversation-card small {
  color: #53636e;
  font-weight: 700;
}

.conversation-card p {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.question-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

.question-screen .screen-grid {
  align-items: stretch;
}

.progress-pill {
  min-width: 112px;
  padding: 10px 16px;
  border-radius: 999px;
  background: #1f2a32;
  color: white;
  font-weight: 800;
  text-align: center;
}

.question-prompt {
  min-height: 92px;
  width: 100%;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  padding: 18px;
  border-radius: 8px;
  background: #eaf4ee;
  color: #1f2a32;
  font-size: 2.5rem;
  font-weight: 900;
  text-align: center;
  overflow-wrap: anywhere;
  word-break: normal;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.choice-button {
  width: 100%;
  min-height: 76px;
  padding: 14px;
  border: 2px solid #7aa78b;
  border-radius: 8px;
  background: white;
  color: #1f2a32;
  font-size: 1.15rem;
  font-weight: 800;
  overflow-wrap: anywhere;
  word-break: normal;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.choice-button:not(:disabled):hover {
  transform: translateY(-2px);
  background: #f3fbf6;
}

.choice-button:disabled {
  opacity: 1;
}

.choice-correct {
  border-color: #2e8b57;
  background: #dff4e7;
}

.choice-selected:not(.choice-correct) {
  border-color: #c75b52;
  background: #fde8e5;
}

.typing-answer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: stretch;
}

.typing-answer-form .form-control {
  min-height: 58px;
  border: 2px solid #7aa78b;
  border-radius: 8px;
  font-weight: 800;
}

.hint-box,
.sentence-translation {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fffdf4;
  border: 1px solid #e4c75b;
  color: #2f3437;
  font-weight: 700;
}

.hint-box {
  display: grid;
  gap: 4px;
}

.hint-box strong {
  color: #37684a;
}

.result-message {
  display: grid;
  gap: 4px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 800;
}

.result-message.correct {
  background: #dff4e7;
  color: #175c34;
}

.result-message.incorrect {
  background: #fde8e5;
  color: #8a2d26;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.result-summary div {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: 8px;
  background: #f3f7fa;
}

.result-summary span {
  color: #53636e;
  font-weight: 700;
}

.result-summary strong {
  font-size: 2rem;
}

.word-list-section {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.word-list-section h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 900;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.word-list {
  display: grid;
  gap: 10px;
}

.word-list-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid rgba(31, 42, 50, 0.12);
  border-radius: 8px;
  background: #fff;
}

.word-list-item div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}

.word-list-item strong {
  font-size: 1.1rem;
}

.word-list-item span,
.word-list-item small {
  color: #53636e;
  font-weight: 700;
}

.mistake-count {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: #fde8e5;
  color: #8a2d26;
  font-size: 0.9rem;
}

.muted-text {
  margin: 0;
  color: #53636e;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px 0;
  border-bottom: 1px solid rgba(31, 42, 50, 0.12);
}

.toggle-row small {
  display: block;
  margin-top: 4px;
  color: #53636e;
}

.toggle-row .form-check-input {
  width: 3rem;
  height: 1.5rem;
  flex: 0 0 auto;
}

.field-stack {
  display: grid;
  gap: 10px;
  padding: 18px 0;
  border-bottom: 1px solid rgba(31, 42, 50, 0.12);
}

.field-stack small {
  display: block;
  margin-top: 4px;
  color: #53636e;
}

.character-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.character-option-card {
  position: relative;
  display: grid;
  grid-template-rows: 180px auto;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 2px solid rgba(31, 42, 50, 0.14);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.character-option-card:hover,
.character-option-card:has(input:checked) {
  border-color: #2e8b57;
  background: #f4fbf6;
  box-shadow: 0 8px 18px rgba(46, 139, 87, 0.14);
}

.character-option-card input {
  position: absolute;
  inset: 12px 12px auto auto;
  width: 1.15rem;
  height: 1.15rem;
}

.character-option-card img {
  width: 100%;
  height: 180px;
  object-fit: contain;
}

.character-option-card span {
  color: #1f2a32;
  font-weight: 900;
  text-align: center;
}

.reset-link {
  margin-top: 14px;
  padding-left: 0;
}

@media (max-width: 860px) {
  body {
    background-attachment: scroll;
  }

  .title-screen,
  .screen-grid {
    grid-template-columns: 1fr;
  }

  .title-screen {
    display: grid;
  }

  .app-screen {
    align-items: start;
  }

  .home-side-panel {
    position: static;
  }

  .home-side-panel .character-image,
  .question-screen .character-image {
    max-height: 320px;
  }

  .question-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .app-container {
    width: min(100% - 20px, 1120px);
    padding: 16px 0 calc(24px + env(safe-area-inset-bottom));
  }

  .app-nav .container-fluid {
    padding-right: 10px;
    padding-left: 10px;
  }

  .app-nav .navbar-collapse {
    padding: 4px 0 10px;
  }

  .app-nav .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .ios-install-tip {
    align-items: stretch;
    flex-direction: column;
  }

  .ios-install-tip button {
    width: 100%;
  }

  .main-panel,
  .settings-panel {
    padding: 18px;
  }

  .choice-grid,
  .course-card-grid,
  .level-status-list,
  .compact-level-list,
  .character-option-grid,
  .typing-answer-form,
  .result-summary {
    grid-template-columns: 1fr;
  }

  .study-mode-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-row {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .action-row > form,
  .action-row > .btn,
  .action-row > form > .btn,
  .compact-action-row .btn-primary {
    width: 100%;
    min-width: 0;
  }

  .main-panel h1,
  .settings-panel h1,
  .question-header h1 {
    font-size: 1.75rem;
  }

  .lead-text,
  .helper-text {
    font-size: 1rem;
  }

  .course-picker-panel,
  .course-level-section {
    padding: 14px;
  }

  .level-status-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .level-status-item small {
    text-align: left;
  }

  .question-prompt {
    min-height: 76px;
    padding: 14px;
    font-size: 1.75rem;
  }

  .choice-button {
    min-height: 64px;
    font-size: 1.05rem;
  }

  .word-list-item,
  .section-title-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .mistake-count {
    align-self: flex-start;
  }

  .character-image {
    max-height: 280px;
  }
}

@media (max-width: 360px) {
  .study-mode-grid {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  .choice-button:not(:disabled):hover,
  .btn-check:checked + .course-card {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }

  .app-screen {
    min-height: calc(100dvh - 120px);
  }
}
