:root {
  --ink: #3f342e;
  --muted: #806f64;
  --orange: #ff8a34;
  --orange-dark: #d85f0f;
  --cream: #fffaf0;
  --blue: #4d91ff;
  --green: #36a96f;
  --red: #d95e55;
  --shadow: 0 18px 55px rgba(68, 48, 35, .12);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; background: #f7f2e9; }
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.screen { min-height: 100vh; }

.parent-screen { padding: 28px clamp(18px, 4vw, 56px) 48px; background: radial-gradient(circle at 90% 0, #ffe9c6 0, transparent 25%), #f8f6f1; }
.parent-topbar { max-width: 1180px; margin: auto; display: flex; align-items: center; gap: 16px; }
.parent-topbar > div { flex: 1; }
.parent-topbar h1 { margin: 2px 0 0; font: 800 clamp(24px, 3vw, 34px)/1.1 Georgia, serif; color: #3a4d5e; }
.eyebrow, .section-kicker, .child-kicker { margin: 0; color: var(--orange-dark); font-size: 12px; letter-spacing: .12em; font-weight: 800; text-transform: uppercase; }
.icon-button, .round-back { width: 48px; height: 48px; border: 0; border-radius: 50%; background: white; font-size: 32px; color: var(--ink); box-shadow: 0 7px 22px rgba(63,52,46,.1); }
.quiet-button { min-height: 44px; padding: 0 18px; border: 1px solid #e6d8c9; border-radius: 14px; color: #725f54; background: rgba(255,255,255,.78); font-weight: 700; }
.tabs { max-width: 1180px; margin: 28px auto 20px; display: flex; gap: 8px; border-bottom: 1px solid #dfd7cc; }
.tabs button { position: relative; border: 0; padding: 13px 17px; color: #8b7a70; background: transparent; font-weight: 700; }
.tabs button.active { color: var(--orange-dark); }
.tabs button.active::after { content: ""; position: absolute; height: 3px; border-radius: 3px; background: var(--orange); inset: auto 10px -2px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 12px; color: white; background: var(--orange); font-size: 11px; }
.parent-grid { max-width: 1180px; margin: auto; display: grid; grid-template-columns: 1.65fr .8fr; gap: 20px; align-items: start; }
.panel { background: rgba(255,255,255,.94); border: 1px solid rgba(123,97,74,.09); border-radius: 24px; box-shadow: var(--shadow); padding: clamp(20px, 3vw, 30px); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-heading h2 { margin: 4px 0 0; color: #3a4d5e; font-size: 23px; }
.ready-count, .status { border-radius: 99px; padding: 7px 11px; background: #e9f8ef; color: #268356; font-size: 12px; font-weight: 800; white-space: nowrap; }
.helper { color: var(--muted); line-height: 1.6; font-size: 14px; }
.add-form { margin: 22px 0; padding: 18px; border-radius: 18px; background: #fff8e8; }
.add-form label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 800; }
.input-row { display: flex; gap: 10px; }
.input-row input { min-width: 0; flex: 1; height: 46px; border: 1.5px solid #e9d7bd; border-radius: 12px; padding: 0 14px; outline: none; background: white; color: var(--ink); }
.input-row input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,138,52,.13); }
.input-row input.invalid { border-color: var(--red); }
.field-hint { min-height: 18px; margin: 7px 2px 0; font-size: 12px; color: #8b796a; }
.field-hint.error { color: var(--red); font-weight: 700; }
.primary-button { min-height: 46px; padding: 0 20px; border: 0; border-radius: 13px; color: white; background: linear-gradient(135deg, #ff9d42, #f37b28); font-weight: 800; box-shadow: 0 9px 20px rgba(240,119,38,.2); }
.primary-button:disabled { color: #a89789; background: #ece6df; box-shadow: none; cursor: default; }
.primary-button.compact { min-width: 78px; }
.word-list { display: grid; gap: 10px; }
.word-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 14px 12px 14px 16px; border: 1px solid #ece4da; border-radius: 15px; transition: .2s; }
.word-row.disabled { opacity: .55; background: #f7f5f2; }
.word-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.word-main strong { color: #354f66; font-size: 19px; }
.word-main span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.status.off { color: #786c65; background: #eeeae5; }
.row-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; border-top: 1px solid #f0e9e1; padding-top: 9px; }
.row-actions button, .card-actions button { min-height: 36px; border: 0; border-radius: 10px; padding: 0 11px; color: #5d7180; background: #f1f5f6; font-size: 12px; font-weight: 800; }
.row-actions button[data-action="delete-word"], .card-actions button[data-action="delete-sentence"] { color: #a85249; background: #fff0ed; }
.save-bar { margin: 22px -30px -30px; padding: 17px 30px; border-radius: 0 0 24px 24px; background: #fbf8f3; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.save-bar div { display: flex; flex-direction: column; gap: 3px; }
.save-bar strong { color: #315c4a; font-size: 14px; }
.save-bar span { color: var(--muted); font-size: 12px; }
.text-button, .state-link { border: 0; color: var(--orange-dark); background: transparent; font-weight: 800; }
.sentence-card { margin-top: 14px; padding: 15px; border: 1px solid #ede2d5; border-radius: 15px; background: #fffdf8; }
.sentence-card p { margin: 0 0 9px; font: 700 15px/1.5 Georgia, serif; color: #4c5963; }
.sentence-card span { font-size: 12px; color: #8f7b6d; }
.card-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; padding-top: 9px; border-top: 1px solid #f0e9e1; }
.notice { display: flex; gap: 10px; margin-top: 18px; padding: 14px; border-radius: 14px; background: #eef7ff; color: #4f6d82; font-size: 13px; line-height: 1.5; }
.notice p { margin: 0; }
.state-link { display: block; margin: 18px auto 0; color: #708391; font-size: 12px; text-decoration: underline; }

.child-screen { position: relative; overflow: hidden; padding: 18px; background: linear-gradient(180deg, #fff9e7, #edf8ff); }
.storybook-bg { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 75% 15%, rgba(255,219,113,.65), transparent 15%), linear-gradient(175deg, transparent 55%, #bfe9f8 56%, #73c7df 78%, #eac78f 79%); }
.storybook-bg span { position: absolute; font-size: clamp(50px, 9vw, 100px); filter: drop-shadow(0 8px 10px rgba(50,80,90,.12)); }
.storybook-bg span:nth-child(1) { top: 8%; right: 10%; }
.storybook-bg span:nth-child(2) { bottom: 14%; left: 11%; }
.storybook-bg span:nth-child(3) { bottom: 3%; right: 12%; letter-spacing: -.5em; }
.child-topbar, .game-topbar { position: relative; z-index: 1; max-width: 880px; margin: auto; display: flex; align-items: center; gap: 14px; }
.book-label { flex: 1; display: flex; flex-direction: column; }
.book-label span { color: #6b7a83; font-size: 12px; font-weight: 700; }
.book-label strong { color: #395266; font: 800 18px Georgia, serif; }
.page-pill { padding: 8px 12px; border-radius: 99px; color: #268356; background: white; font-size: 12px; font-weight: 800; }
.finish-card { position: relative; z-index: 1; width: min(560px, calc(100% - 24px)); margin: clamp(50px, 11vh, 110px) auto 0; padding: 58px clamp(24px, 6vw, 54px) 36px; text-align: center; border: 2px solid rgba(255,255,255,.8); border-radius: 32px; background: rgba(255,255,255,.91); box-shadow: 0 24px 70px rgba(41,94,111,.18); backdrop-filter: blur(8px); }
.celebration { position: absolute; top: -38px; left: 50%; display: grid; place-items: center; width: 76px; height: 76px; transform: translateX(-50%) rotate(-6deg); border: 5px solid white; border-radius: 25px; background: #ffd65a; color: white; font-size: 42px; box-shadow: 0 12px 25px rgba(210,155,26,.24); }
.finish-card h1, .result-card h1 { margin: 8px 0 9px; color: #38566c; font-size: clamp(28px, 6vw, 38px); }
.finish-card > p:not(.child-kicker) { margin: 0 0 22px; color: #75665c; }
.finish-card .pool-note { display: inline-block; margin: 0 0 12px; padding: 7px 11px; border-radius: 99px; color: #34755d; background: #eaf8f0; font-size: 12px; font-weight: 800; }
.play-button { width: 100%; min-height: 78px; border: 0; border-radius: 22px; color: white; background: linear-gradient(135deg, #ff9d35, #f6752d); box-shadow: 0 14px 28px rgba(238,112,35,.3), inset 0 1px rgba(255,255,255,.35); display: grid; grid-template-columns: 48px 1fr; grid-template-rows: 1fr 1fr; text-align: left; align-items: center; padding: 12px 22px; }
.play-button span { grid-row: 1/3; font-size: 34px; }
.play-button strong { align-self: end; font-size: 22px; }
.play-button small { align-self: start; opacity: .85; font-weight: 700; }
.secondary-actions { display: flex; justify-content: center; gap: 8px; margin-top: 15px; }
.secondary-actions button, .home-button { min-height: 46px; padding: 0 18px; border: 0; border-radius: 14px; color: #65584f; background: transparent; font-weight: 800; }
.secondary-actions button:hover { background: #f5f0e9; }
.corner-link { position: absolute; z-index: 2; right: 18px; bottom: 15px; border: 0; background: rgba(255,255,255,.7); color: #5d7787; border-radius: 99px; padding: 9px 12px; font-size: 11px; }

.game-screen { background: radial-gradient(circle at 10% 5%, #ffe6aa 0, transparent 28%), radial-gradient(circle at 95% 85%, #c9ecff 0, transparent 30%), #fffaf1; }
.game-topbar { width: min(780px, 100%); }
.progress-wrap { flex: 1; text-align: center; color: #657984; font-size: 13px; font-weight: 800; }
.progress-track { width: min(300px, 80%); height: 9px; margin: 7px auto 0; border-radius: 8px; overflow: hidden; background: #e7ddd0; }
.progress-track i { display: block; width: 33%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ffad44, #ff7c34); transition: width .3s; }
.star-score { min-width: 48px; color: #c47e00; font-size: 19px; }
.game-card { width: min(760px, 100%); margin: 18px auto 0; padding: clamp(20px, 4vw, 36px); border-radius: 32px; background: rgba(255,255,255,.92); box-shadow: var(--shadow); text-align: center; }
.mascot { font-size: 54px; transition: transform .25s; }
.mascot.bounce { transform: translateY(-9px) rotate(5deg); }
.game-card h1 { margin: 3px 0 16px; color: #3a566b; font-size: clamp(25px, 5vw, 34px); }
.listen-button { min-width: min(330px, 100%); min-height: 68px; border: 3px solid #ffc76b; border-radius: 22px; color: #a75213; background: #fff4d7; font-size: 18px; font-weight: 800; box-shadow: 0 8px 0 #f3d393; }
.listen-button span { margin-right: 8px; font-size: 24px; }
.listen-button.playing { transform: translateY(5px); box-shadow: 0 3px 0 #f3d393; }
.context-label { margin: 19px 0 7px; color: #8b7a70; font-size: 12px; }
.context-button { min-height: 44px; border: 0; border-radius: 14px; padding: 0 16px; color: #45728d; background: #edf8ff; font-weight: 800; }
.answer-slots { min-height: 69px; margin: 25px 0 8px; display: flex; justify-content: center; gap: clamp(5px, 1.6vw, 10px); }
.answer-slot { width: clamp(40px, 9vw, 58px); height: 62px; display: grid; place-items: center; border: 3px dashed #d8c9b7; border-radius: 16px; color: #3e5869; background: #fffdf8; font: 900 clamp(23px, 5vw, 30px) Georgia, serif; text-transform: lowercase; }
.answer-slot.filled { border-style: solid; border-color: #73b7e1; background: #eef9ff; }
.answer-slots.wrong .answer-slot { border-color: #e79a8e; background: #fff2ef; animation: shake .25s; }
.answer-slots.correct .answer-slot { border-color: #63bd8b; background: #eaf9f0; }
.feedback { min-height: 24px; margin: 5px 0 17px; color: #837267; font-weight: 800; }
.feedback.wrong { color: #b34f45; }
.feedback.correct { color: #218357; }
.letter-tiles { min-height: 74px; display: flex; flex-wrap: wrap; justify-content: center; gap: 11px; }
.letter-tile { width: 60px; height: 64px; border: 2px solid #e0d4c5; border-radius: 18px; color: #425c6e; background: white; box-shadow: 0 7px 0 #ddd0c0; font: 900 30px Georgia, serif; }
.letter-tile:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 3px 0 #ddd0c0; }
.letter-tile:disabled { opacity: .18; box-shadow: none; cursor: default; }
.game-actions { margin-top: 23px; display: flex; justify-content: center; gap: 10px; }
.undo-button, .skip-button { min-width: 128px; min-height: 48px; border: 0; border-radius: 15px; color: #5c7180; background: #eef3f5; font-weight: 800; }
.undo-button:disabled { opacity: .35; cursor: default; }
.skip-button { min-width: auto; background: transparent; font-size: 12px; text-decoration: underline; }

.result-screen { display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #ffe49b, transparent 24%), radial-gradient(circle at 85% 85%, #b9e9ff, transparent 30%), #fff9ed; }
.confetti { position: absolute; top: 5%; width: 100%; color: #ff9b43; text-align: center; font-size: clamp(20px, 5vw, 42px); letter-spacing: 1.2em; }
.result-card { position: relative; width: min(590px, 100%); padding: 28px clamp(22px, 5vw, 44px); border-radius: 32px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); text-align: center; }
.result-mascot { font-size: 62px; }
.result-card h1 span { color: var(--orange-dark); }
.result-list { margin: 22px 0; display: grid; gap: 9px; text-align: left; }
.result-item { min-height: 56px; padding: 11px 15px; border-radius: 16px; background: #edf9f2; display: flex; align-items: center; justify-content: space-between; }
.result-item.retry-item { background: #fff4e4; }
.result-item strong { color: #3b5669; font: 800 18px Georgia, serif; }
.result-item span { color: #2b8659; font-size: 13px; font-weight: 800; }
.result-item.retry-item span { color: #b26624; }
.play-button.retry { min-height: 70px; background: linear-gradient(135deg, #64c686, #34a76c); box-shadow: 0 12px 25px rgba(52,167,108,.25); }
.home-button { margin-top: 10px; }

.modal { position: fixed; z-index: 20; inset: 0; padding: 20px; display: grid; place-items: center; background: rgba(41,39,37,.45); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: min(660px, 100%); max-height: 90vh; overflow: auto; border-radius: 25px; padding: 28px; background: white; box-shadow: 0 25px 80px rgba(0,0,0,.22); }
.modal-card.small { max-width: 410px; text-align: center; }
.modal-close { position: absolute; right: 15px; top: 15px; width: 44px; height: 44px; border: 0; border-radius: 50%; color: #6e625b; background: #f1ede8; font-size: 23px; }
.modal-card h2 { margin: 0 0 18px; color: #3d586b; }
.state-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.state-card { min-height: 140px; padding: 17px; border: 1px solid #eee4d9; border-radius: 17px; background: #fffcf7; }
.state-card b { display: block; margin: 9px 0 6px; color: #405b6e; }
.state-card p { margin: 0; color: #7e7067; font-size: 13px; line-height: 1.5; }
.state-card button { margin-top: 12px; min-height: 38px; border: 0; border-radius: 10px; padding: 0 12px; color: white; background: var(--orange); font-weight: 700; }
.loading-dots { color: var(--blue); letter-spacing: 4px; font-size: 21px; animation: pulse 1s infinite alternate; }
.dialog-icon { font-size: 50px; }
.modal-card.small p { color: var(--muted); }
.item-form { text-align: left !important; }
.item-form label { display: block; margin: 8px 0; font-size: 13px; font-weight: 800; }
.item-form input { width: 100%; height: 48px; margin-bottom: 4px; border: 1.5px solid #e3d5c6; border-radius: 12px; padding: 0 13px; outline: none; }
.item-form input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,138,52,.13); }
.item-form .primary-button { width: 100%; margin-top: 14px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 20px; }
.dialog-actions button { flex: 1; min-height: 48px; border: 0; border-radius: 14px; background: #edf4f7; color: #486171; font-weight: 800; }
.dialog-actions .danger-soft { color: #a85249; background: #fff0ed; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 12px 18px; border-radius: 99px; color: white; background: rgba(53,48,45,.9); font-weight: 700; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes pulse { to { opacity: .35; } }
@media (max-width: 760px) {
  .parent-grid { grid-template-columns: 1fr; }
  .quiet-button { font-size: 12px; padding: 0 10px; }
  .tabs { overflow-x: auto; }
  .tabs button { white-space: nowrap; }
  .save-bar { margin-left: -20px; margin-right: -20px; margin-bottom: -20px; padding: 16px 20px; }
  .state-grid { grid-template-columns: 1fr; }
  .word-row { grid-template-columns: 1fr auto; }
}
@media (max-width: 440px) {
  .parent-screen, .child-screen { padding: 14px; }
  .parent-topbar { gap: 9px; }
  .parent-topbar h1 { font-size: 21px; }
  .parent-topbar .eyebrow { font-size: 10px; }
  .finish-card { width: 100%; }
  .game-card { padding: 18px 12px; }
  .letter-tile { width: 52px; height: 58px; }
}
