:root {
  color-scheme: light;
  --ink: #14202f;
  --muted: #62706f;
  --green: #237f6c;
  --green-dark: #0f4a3f;
  --mint: #dbecea;
  --cream: #fff8ec;
  --paper: #ffffff;
  --line: #cfe0dd;
  --orange: #f58a32;
  --shadow: 0 18px 40px rgba(15, 74, 63, 0.14);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #edf5f1;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  min-width: 0;
  min-height: 48px;
  color: var(--green-dark);
  background: var(--mint);
  font-weight: 800;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  width: min(720px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(22px, env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0 14px;
  background: rgba(237, 245, 241, 0.94);
  backdrop-filter: blur(16px);
}

.brand-mark,
.lesson-number {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  font-weight: 900;
}

.brand-mark {
  width: 52px;
  height: 52px;
  background: #ffdc55;
  color: var(--green-dark);
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.1;
}

.icon-btn {
  margin-left: auto;
  width: 52px;
  min-height: 52px;
  border-radius: 50%;
  font-size: 24px;
}

main {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.lesson-card,
.player-card,
.setup-card,
.page-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.lesson-card {
  padding: 14px;
}

.lesson-title-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.lesson-title-row > div {
  min-width: 0;
}

.lesson-number {
  width: 56px;
  height: 56px;
  background: #dd4c74;
  color: #fff;
  font-size: 23px;
}

.lesson-title-row h2 {
  margin-bottom: 5px;
  font-size: 22px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.lesson-title-row p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.lesson-strip {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}

.lesson-strip::-webkit-scrollbar {
  display: none;
}

.lesson-pill {
  min-width: 50px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 14px;
}

.lesson-pill.is-active {
  background: var(--green);
  color: white;
}

.player-card {
  padding: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fffaf0 100%);
}

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

.segment-tabs button {
  min-height: 56px;
}

.segment-tabs button.is-active {
  background: var(--green);
  color: #fff;
}

.segment-tabs button.is-missing {
  opacity: 0.55;
}

.now-box {
  margin: 14px 0;
  padding: 16px;
  border-radius: 18px;
  background: var(--cream);
  border: 1px solid #f3d9ae;
}

.now-label {
  margin-bottom: 2px;
  color: var(--orange);
  font-weight: 900;
}

.now-box h2 {
  margin-bottom: 6px;
  font-size: 28px;
}

.now-box p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

.study-text-card {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
}

.study-text-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.study-text-head h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.study-text-head button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 14px;
}

.study-text-body {
  display: grid;
  gap: 8px;
  max-height: 38vh;
  overflow-y: auto;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}

.study-text-card.is-collapsed .study-text-body {
  display: none;
}

.dialog-line {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin: 0;
  padding: 12px;
  border: 1px solid #e5d8bf;
  border-radius: 14px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 850;
  line-height: 1.45;
}

.dialog-line span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 900;
}

.vocab-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.vocab-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  padding: 12px;
  border: 1px solid #e5d8bf;
  border-radius: 14px;
  background: #fffaf0;
}

.vocab-item strong {
  font-size: 22px;
  line-height: 1.25;
}

.vocab-item span,
.vocab-item em,
.empty-text {
  color: var(--muted);
  font-style: normal;
  font-weight: 850;
}

.empty-text {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: #fff;
  line-height: 1.45;
}

.ocr-text {
  margin: 0;
  padding: 14px;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid #e5d8bf;
  border-radius: 14px;
  background: #fffaf0;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Noto Sans JP", "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 17px;
  font-weight: 850;
  line-height: 1.55;
}

.ocr-clean-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #e5d8bf;
  border-radius: 14px;
  background: #fffaf0;
}

.ocr-clean-list p {
  margin: 0;
}

.ocr-heading {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--green-dark);
  font-size: 15px;
  font-weight: 950;
  line-height: 1.25;
}

.ocr-line {
  padding: 10px 12px;
  border: 1px solid #eadfc8;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-family: "Noto Sans JP", "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

audio {
  width: 100%;
}

.time-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  color: var(--muted);
  font-weight: 900;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.primary-controls {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: center;
}

.round-btn {
  min-height: 72px;
  border-radius: 18px;
  font-size: 42px;
}

.play-btn {
  min-height: 84px;
  border-radius: 22px;
  background: var(--green);
  color: #fff;
  font-size: 30px;
}

.jump-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.jump-controls button {
  min-height: 54px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-weight: 900;
}

.toggle-line input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.speed-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.speed-row button {
  min-height: 46px;
}

.speed-row button.is-active {
  background: var(--green-dark);
  color: white;
}

.setup-card,
.page-card {
  padding: 14px;
}

.setup-card.is-hidden {
  display: none;
}

.setup-card h2,
.page-card h2 {
  margin-bottom: 8px;
}

.setup-note {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

.setup-actions {
  display: grid;
  gap: 8px;
}

.setup-actions.compact {
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}

.page-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.page-card-head button {
  padding: 0 18px;
}

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

.page-tabs button {
  min-height: 52px;
}

.page-tabs button.is-active {
  background: var(--green);
  color: #fff;
}

.page-card img {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 12px;
  background: #f8faf8;
}

.page-card.is-collapsed img {
  display: none;
}

.page-card.is-collapsed .page-tabs {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%) translateY(18px);
  max-width: calc(100% - 28px);
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--green-dark);
  color: white;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.drive-mode .app-shell {
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}

body.drive-mode .lesson-card,
body.drive-mode .setup-card,
body.drive-mode .page-card,
body.drive-mode .study-text-card,
body.drive-mode .segment-tabs,
body.drive-mode .speed-row {
  display: none;
}

body.drive-mode .topbar {
  position: static;
}

body.drive-mode .player-card {
  min-height: calc(100vh - 104px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

body.drive-mode .now-box h2 {
  font-size: 38px;
}

body.drive-mode .play-btn {
  min-height: 112px;
  font-size: 38px;
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .lesson-title-row h2 {
    font-size: 19px;
  }

  .segment-tabs,
  .toggle-grid {
    grid-template-columns: 1fr 1fr;
  }

  .jump-controls {
    grid-template-columns: repeat(2, 1fr);
  }

  .setup-actions.compact {
    grid-template-columns: 1fr;
  }
}
