:root {
  color-scheme: light;
  --ink: #2f2345;
  --muted: #746a80;
  --paper: rgba(255, 253, 248, 0.94);
  --cream: #fff7ed;
  --honey: #ffd267;
  --rose: #ef649a;
  --rose-soft: rgba(239, 100, 154, 0.3);
  --teal: #258c82;
  --teal-soft: rgba(37, 140, 130, 0.12);
  --line: rgba(47, 35, 69, 0.12);
  --shadow: 0 18px 48px rgba(77, 55, 38, 0.12);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 0 13%, rgba(255, 180, 142, 0.34), transparent 24rem),
    radial-gradient(circle at 96% 82%, rgba(161, 207, 217, 0.35), transparent 22rem),
    linear-gradient(135deg, #fff9f1, #f4fbf5);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.app-shell {
  width: min(100%, 1080px);
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

.screen {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.home-screen {
  grid-template-rows: auto 1fr;
}

.topbar,
.panel,
.word-card,
.trace-pane,
.home-card {
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 68px;
  border-radius: 28px;
  padding: 10px 14px;
  backdrop-filter: blur(14px);
}

.lesson-screen .topbar,
.trace-screen .topbar {
  min-height: 54px;
  border-radius: 22px;
  padding: 7px 10px;
}

.lesson-screen .brand,
.trace-screen .brand {
  gap: 8px;
}

.lesson-screen .mascot-pair,
.trace-screen .mascot-pair {
  width: 58px;
  height: 38px;
}

.lesson-screen .mascot-face,
.trace-screen .mascot-face {
  top: 4px;
  width: 32px;
  height: 32px;
  border-width: 2px;
}

.lesson-screen .cat-face::before,
.lesson-screen .cat-face::after,
.trace-screen .cat-face::before,
.trace-screen .cat-face::after {
  top: -6px;
  width: 13px;
  height: 13px;
}

.lesson-screen .dog-face::before,
.lesson-screen .dog-face::after,
.trace-screen .dog-face::before,
.trace-screen .dog-face::after {
  width: 10px;
  height: 17px;
}

.lesson-screen .cat-face i,
.lesson-screen .dog-face i,
.trace-screen .cat-face i,
.trace-screen .dog-face i {
  top: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  width: 100%;
}

.brand-mark,
.letter-badge {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--honey);
  color: var(--ink);
  font-weight: 900;
}

.brand-mark {
  width: 48px;
  height: 48px;
  font-size: 16px;
}

.mascot-pair {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  width: 74px;
  height: 52px;
}

.mascot-face {
  position: absolute;
  top: 5px;
  display: block;
  width: 42px;
  height: 42px;
  border: 3px solid rgba(47, 35, 69, 0.08);
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(47, 35, 69, 0.1);
}

.mascot-face::before,
.mascot-face::after {
  position: absolute;
  content: "";
}

.mascot-face i,
.mascot-face i::before,
.mascot-face i::after {
  position: absolute;
  content: "";
}

.cat-face {
  left: 0;
  z-index: 2;
  background: #fff4cf;
}

.dog-face {
  right: 0;
  background: #f6c790;
}

.cat-face::before,
.cat-face::after {
  top: -9px;
  width: 17px;
  height: 17px;
  background: #fff4cf;
  border-radius: 3px;
  transform: rotate(45deg);
}

.cat-face::before {
  left: 5px;
}

.cat-face::after {
  right: 5px;
}

.dog-face::before,
.dog-face::after {
  top: 2px;
  width: 14px;
  height: 23px;
  background: #9c6a4b;
  border-radius: 12px;
}

.dog-face::before {
  left: -5px;
  transform: rotate(18deg);
}

.dog-face::after {
  right: -5px;
  transform: rotate(-18deg);
}

.cat-face i,
.dog-face i {
  left: 50%;
  top: 23px;
  width: 7px;
  height: 5px;
  border-radius: 50%;
  background: #2f2345;
  transform: translateX(-50%);
}

.cat-face i::before,
.cat-face i::after,
.dog-face i::before,
.dog-face i::after {
  top: -13px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #2f2345;
}

.cat-face i::before,
.dog-face i::before {
  left: -12px;
}

.cat-face i::after,
.dog-face i::after {
  right: -12px;
}

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

.brand h1 {
  overflow: hidden;
  font-size: clamp(24px, 6vw, 36px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-screen .brand h1,
.trace-screen .brand h1 {
  font-size: clamp(20px, 5.2vw, 30px);
}

.brand p {
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(12px, 3vw, 15px);
  font-weight: 800;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-screen .brand p,
.trace-screen .brand p {
  font-size: clamp(11px, 2.8vw, 13px);
}

.back-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(47, 35, 69, 0.1);
  font-size: 28px;
  font-weight: 900;
}

.lesson-screen .back-button,
.trace-screen .back-button {
  width: 40px;
  height: 40px;
  font-size: 24px;
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-height: 0;
}

.home-card {
  display: grid;
  align-content: center;
  gap: clamp(8px, 2.3vh, 18px);
  min-height: 0;
  border-radius: 28px;
  padding: clamp(22px, 5vw, 34px);
  text-align: left;
}

.home-card-primary {
  background: linear-gradient(135deg, #35254c, #5a4168);
  color: #fff;
}

.home-card span {
  color: var(--rose);
  font-size: clamp(15px, 4vw, 22px);
  font-weight: 900;
  letter-spacing: 0;
}

.home-card-primary span {
  color: var(--honey);
}

.home-card strong {
  font-size: clamp(38px, 10vw, 58px);
  line-height: 1;
}

.home-card small {
  color: rgba(47, 35, 69, 0.68);
  font-size: clamp(17px, 4.4vw, 26px);
  font-weight: 900;
}

.home-card-primary small {
  color: rgba(255, 255, 255, 0.78);
}

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

.letter-choice-card {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 0;
  border-radius: 26px;
  padding: 18px;
  background: linear-gradient(150deg, #ffffff, #fff5df);
  border: 1px solid rgba(47, 35, 69, 0.1);
  box-shadow: var(--shadow);
  text-align: left;
}

.letter-choice-card strong {
  font-size: clamp(60px, 18vw, 104px);
  line-height: 0.86;
}

.letter-choice-card span {
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(16px, 4vw, 24px);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  display: grid;
  min-height: 0;
  border-radius: 28px;
  padding: 14px;
}

.lesson-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.lesson-head {
  min-height: 0;
}

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

.letter-badge {
  width: clamp(52px, 14vw, 70px);
  height: clamp(52px, 14vw, 70px);
  font-size: clamp(28px, 8vw, 40px);
}

.lesson-title h2 {
  margin: 0;
  font-size: clamp(30px, 8vw, 46px);
  line-height: 1;
}

.lesson-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: clamp(13px, 3.4vw, 17px);
  font-weight: 900;
}

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

.word-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 5px;
  min-width: 0;
  min-height: 0;
  border-radius: 24px;
  padding: 10px;
  text-align: center;
}

.word-image-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  border-radius: 18px;
  background: #fff;
}

.word-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.word-name {
  overflow: hidden;
  font-size: clamp(24px, 6vw, 40px);
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-cn {
  color: var(--muted);
  font-size: clamp(14px, 3.6vw, 20px);
  font-weight: 900;
  line-height: 1.05;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
}

.sound-button,
.secondary-button,
.finish-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: clamp(15px, 4vw, 21px);
  font-weight: 900;
  white-space: nowrap;
}

.sound-button {
  background: var(--ink);
  color: #fff;
}

.secondary-button {
  background: #fff;
  border: 1px solid var(--line);
}

.finish-button {
  background: var(--honey);
}

.trace-panel {
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.trace-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
}

.trace-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  min-height: 0;
  border-radius: 22px;
  padding: 10px;
}

.pane-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--rose);
  font-size: clamp(14px, 3.7vw, 18px);
  font-weight: 900;
  line-height: 1;
}

.pane-head span:last-child {
  color: var(--ink);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 4px dashed rgba(239, 100, 154, 0.52);
  border-radius: 18px;
  background: rgba(255, 250, 241, 0.72);
  touch-action: none;
}

.hidden {
  display: none;
}

@media (orientation: portrait) {
  .home-actions {
    grid-template-columns: 1fr;
  }

  .letter-choice-grid {
    grid-template-columns: 1fr;
  }

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

@media (orientation: landscape) {
  .app-shell {
    width: 100%;
    max-width: 1180px;
    padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  }

  .screen {
    gap: 8px;
  }

  .home-screen {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .home-screen .topbar {
    min-height: 56px;
  }

  .home-actions {
    min-height: 0;
  }

  .lesson-panel {
    grid-template-columns: minmax(164px, 0.34fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .lesson-head {
    align-self: stretch;
  }

  .lesson-title {
    height: 100%;
    align-content: center;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    text-align: center;
  }

  .word-grid {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .lesson-panel .action-row {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
  }
}

@media (max-height: 720px) {
  .app-shell {
    padding-block: max(7px, env(safe-area-inset-top)) max(7px, env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 56px;
    border-radius: 22px;
    padding: 8px 10px;
  }

  .brand-mark,
  .back-button {
    width: 42px;
    height: 42px;
  }

  .mascot-pair {
    width: 62px;
    height: 42px;
  }

  .mascot-face {
    width: 34px;
    height: 34px;
    border-width: 2px;
  }

  .cat-face::before,
  .cat-face::after {
    top: -7px;
    width: 14px;
    height: 14px;
  }

  .dog-face::before,
  .dog-face::after {
    width: 11px;
    height: 18px;
  }

  .cat-face i,
  .dog-face i {
    top: 19px;
  }

  .panel {
    border-radius: 22px;
    padding: 10px;
  }

  .home-card {
    border-radius: 22px;
    padding: 18px;
  }

  .letter-choice-card {
    border-radius: 22px;
    padding: 14px;
  }

  .word-card {
    border-radius: 18px;
    padding: 8px;
  }

  .sound-button,
  .secondary-button,
  .finish-button {
    min-height: 38px;
    font-size: 15px;
  }
}

@media (max-width: 360px) {
  .word-grid,
  .action-row {
    gap: 8px;
  }

  .sound-button,
  .secondary-button,
  .finish-button {
    padding-inline: 8px;
  }
}
