
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ===== Base ===== */
:root { font-family: Nunito, Arial, sans-serif; color: #29243a; background: #fbf9ff; font-synthesis: none; --purple: #7650b5; --purple-soft: #eee5fb; --green: #208b55; --green-soft: #e0f6e9; --surface: #fff; --muted: #746e82; --shadow: 0 5px 18px #31234b10; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: radial-gradient(ellipse at top left, #f0e8ff 0, transparent 40%), radial-gradient(ellipse at top right, #e4f7eb 0, transparent 35%), #fbf9ff; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #d7c4ff; outline-offset: 2px; }
[hidden] { display: none !important; }
#app { width: min(1050px, 100%); margin: 0 auto; padding: 8px clamp(10px, 2vw, 20px); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ===== Header ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-icon { font-size: 1.8rem; }
.brand h1 { margin: 0; font-size: clamp(1.3rem, 3vw, 1.7rem); line-height: 1; font-weight: 900; letter-spacing: -.04em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .78rem; }

/* ===== Setup and results ===== */
.setup-wrap, .result-wrap { display: grid; place-items: center; flex: 1; }
.setup-card, .result-card { width: min(560px, 100%); background: #fff; border: 1px solid #eee8f7; border-radius: 18px; padding: clamp(16px, 4vw, 28px); box-shadow: var(--shadow); }
.setup-heading { display: flex; justify-content: center; align-items: center; gap: 16px; font-size: 2.2rem; }
.versus { font-size: .9rem; font-weight: 900; color: #9288a5; background: #f4f0fa; border-radius: 99px; padding: 8px; }
.setup-card h2, .result-card h2 { text-align: center; font-size: 1.45rem; margin: 8px 0 4px; }
.muted { color: var(--muted); }
.setup-card > .muted { text-align: center; margin: 0 0 12px; }
.setup-card label { display: block; font-weight: 800; font-size: .86rem; margin: 10px 0 4px; }
.setup-card input, .setup-card select { width: 100%; min-height: 40px; border: 1px solid #ded7e9; border-radius: 10px; padding: 8px 10px; background: #fff; color: #29243a; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.primary-btn, .secondary-btn, .small-btn { border: 0; border-radius: 10px; font-weight: 900; transition: transform .15s, filter .15s; }
.primary-btn { background: var(--purple); color: #fff; padding: 10px 16px; box-shadow: 0 3px 0 #4f3484; }
.primary-btn:hover, .secondary-btn:hover, .small-btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.primary-btn:disabled, .small-btn:disabled { cursor: not-allowed; transform: none; }
.setup-card .primary-btn { width: 100%; margin-top: 14px; }
.small-btn { background: #f0ebf7; color: #4f4265; padding: 7px 10px; }
.secondary-btn { background: #f0ebf7; color: #514663; padding: 8px 12px; }
.error { color: #bd3030; font-weight: 700; min-height: 1em; margin: 6px 0 0; }

/* ===== Setup toggle buttons ===== */
.toggle-group { display: flex; width: 100%; gap: 6px; margin-top: 6px; }
.toggle-btn { flex: 1 1 0; min-width: 0; padding: 10px 6px; border: 1px solid #d8d5e2; border-radius: 10px; background: #f7f6fa; color: #514b60; font-size: .9rem; font-weight: 700; cursor: pointer; transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease, transform 180ms ease; }
.toggle-btn:hover { border-color: #a99acb; transform: translateY(-1px); }
.toggle-btn.active { background: #7650b8; border-color: #7650b8; color: #fff; box-shadow: 0 2px 5px rgba(70, 45, 110, .18); }
#language-options .toggle-btn.active { background: #239b67; border-color: #239b67; box-shadow: 0 2px 5px rgba(25, 122, 80, .18); }
.toggle-btn:focus-visible { outline: 3px solid #b9a4e8; outline-offset: 2px; }

/* ===== Scoreboard ===== */
.scoreboard { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 8px; }
.team-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; row-gap: 3px; border: 2px solid transparent; border-radius: 14px; text-align: left; padding: 7px 10px; min-width: 0; transition: box-shadow .15s, transform .15s; }
.panda-panel { background: var(--purple-soft); color: #57378b; border-color: #d8c4f4; }
.dragon-panel { background: var(--green-soft); color: #176b40; border-color: #b9e8ca; }
.team-panel.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px currentColor; transform: translateY(-1px); }
.team-name { grid-column: 1; grid-row: 1; display: flex; align-items: center; justify-content: flex-start; gap: 4px; min-width: 0; font-weight: 900; font-size: .9rem; overflow-wrap: anywhere; }
.team-name span:first-child { font-size: 1.15rem; flex-shrink: 0; }
.score { grid-column: 2; grid-row: 1; font-size: clamp(1.3rem, 3vw, 1.8rem); font-weight: 900; line-height: 1; margin: 0; text-align: right; }
.time-label { grid-column: 1; grid-row: 2; font-size: .67rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 800; opacity: .75; }
.clock { grid-column: 2; grid-row: 2; font-size: .95rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; text-align: right; }
.versus-badge { font-size: .72rem; font-weight: 900; color: #9387a8; background: #fff; padding: 8px; border-radius: 50%; box-shadow: var(--shadow); }
.turn-banner { text-align: center; border-radius: 10px; padding: 7px 10px; margin: 0 0 8px; font-weight: 900; font-size: .95rem; }
.panda-turn { background: var(--purple); color: #fff; }
.dragon-turn { background: var(--green); color: #fff; }

/* ===== Game card ===== */
.play-card { background: #fff; border: 1px solid #eee8f7; border-radius: 16px; padding: clamp(10px, 2vw, 16px); box-shadow: var(--shadow); }
.sentence-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .75rem; font-weight: 800; }

/* ===== Chinese character tiles ===== */
.sentence { display: flex; justify-content: center; align-items: flex-start; flex-wrap: wrap; gap: 6px; margin: 12px 0 8px; min-height: 88px; }
.char-tile { appearance: none; -webkit-appearance: none; flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 61px; min-height: 83px; padding: 6px 8px; border: 2px solid #e7e0ef; border-radius: 10px; background: #fff; color: #29243a; font-family: KaiTi, Kaiti, serif; font-size: clamp(2.1rem, 4.8vw, 3rem); line-height: 1.15; overflow: visible; }
.char-tile > span:first-child { display: block; flex: 0 0 auto; min-height: 1.15em; font-family: KaiTi, Kaiti, serif; font-size: 1em; line-height: 1.15; color: inherit; white-space: nowrap; }
.char-tile .tile-pin { display: block; flex: 0 0 1.3em; width: 100%; height: 1.3em; min-height: 1.3em; font-family: Nunito, Arial, sans-serif; font-size: .85rem; font-weight: 900; line-height: 1.3em; text-align: center; color: #8e879b; white-space: nowrap; overflow: visible; }
.char-tile.done { opacity: .65; background: #f6f4f8; }
.char-tile.selected { border-color: currentColor; box-shadow: 0 0 0 3px #f2edf9; }
.panda-theme .char-tile.selected { color: var(--purple); background: #f7f1ff; }
.dragon-theme .char-tile.selected { color: var(--green); background: #effbf3; }
.char-tile.punctuation { min-width: 22px; padding-left: 2px; padding-right: 2px; border-color: transparent; background: transparent; }

/* ===== Instruction and answer controls ===== */
.instruction { text-align: center; font-weight: 700; font-size: .86rem; margin: 0 0 8px; }
.answer-row { display: flex; align-items: center; flex-wrap: nowrap; gap: 7px; min-width: 0; }
.answer-box { display: grid; grid-template-columns: 35px 22px minmax(0, 1fr); align-items: center; justify-content: start; gap: 0; box-sizing: border-box; flex: 0 0 150px; width: 150px; min-width: 150px; height: 50px; min-height: 50px; padding: 0 6px; overflow: hidden; background: #f8f6fb; border: 1px solid #e8e2f0; border-radius: 10px; }
.selected-char { display: flex; align-items: center; justify-content: center; box-sizing: border-box; width: 32px; min-width: 32px; height: 32px; margin: 0; padding: 0; font-family: KaiTi, Kaiti, serif; font-size: 1.4rem; font-weight: 800; line-height: 1; white-space: nowrap; flex-shrink: 0; }
.answer-arrow { display: flex; align-items: center; justify-content: center; width: 14px; height: 24px; color: #a49ab4; line-height: 1; }
.answer-preview { display: block; box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; height: 24px; margin: 0; padding: 0; overflow: hidden; white-space: nowrap; text-overflow: clip; font-size: 1rem; font-weight: 900; line-height: 24px; letter-spacing: 0; }

/* ===== OK button ===== */
#ok-btn { box-sizing: border-box; flex: 0 0 112px; width: 112px; min-width: 112px; height: 46px; min-height: 46px; padding: 8px 12px; border: 2px solid transparent; border-radius: 12px; font-size: 1.08rem; font-weight: 900; white-space: nowrap; box-shadow: 0 3px 0 #0002; align-self: center; transition: background-color 180ms ease, border-color 180ms ease, transform 150ms ease, box-shadow 150ms ease; }
#ok-btn.team-panda { background: #8056c7; border-color: #6941ad; color: #fff; }
#ok-btn.team-dragon { background: #269765; border-color: #19794f; color: #fff; }
#ok-btn:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 4px 0 #0002; }
#ok-btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 #0002; }
#ok-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ===== Other answer controls ===== */
#clear-btn { flex: 0 0 auto; padding: 8px 9px; white-space: nowrap; }
#restart-btn { background: #f8d7da; color: #842029; border: 1px solid #f1bfc4; }
#restart-btn:hover { background: #f1c2c7; }
#restart-btn:disabled { opacity: .7; cursor: not-allowed; }

/* ===== Keyboard ===== */
.keyboard { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin-top: 8px; }
.key { min-width: 0; min-height: 36px; border: 1px solid #e4ddec; border-radius: 8px; background: #fff; color: #302941; font-weight: 900; font-size: .95rem; box-shadow: 0 2px 0 #e5deed; }
.key:active { transform: translateY(1px); box-shadow: none; }
.key.special { background: #f1edf7; color: #65577a; }
.key:disabled { opacity: .3; cursor: not-allowed; }

/* ===== Feedback ===== */
.feedback { flex: 1 1 120px; min-width: 0; min-height: 22px; margin: 0; text-align: left; font-weight: 900; font-size: .78rem; line-height: 1.2; overflow-wrap: anywhere; }
.feedback.good { color: #16864c; }
.feedback.bad { color: #c13e3e; }

/* ===== Results ===== */
.result-card { text-align: center; }
.trophy { font-size: 3rem; }
.result-card h2 { font-size: 1.7rem; }
.final-scores { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.final-team { border-radius: 12px; padding: 12px 6px; display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }
.final-team strong { font-size: 1.8rem; }
.result-card .primary-btn { width: 100%; }

/* ===== Footer ===== */
footer { text-align: center; color: #968da5; font-size: .7rem; padding: 10px 0 2px; }

/* ===== Skip button ===== */
.skip-btn { box-sizing: border-box; flex: 0 0 auto; height: 46px; min-height: 46px; padding: 8px 12px; background: #f0edf5; color: #62596f; border: 1px solid #dcd5e7; border-radius: 12px; font: inherit; font-size: .88rem; font-weight: 800; cursor: pointer; box-shadow: none; transition: background-color 180ms ease, border-color 180ms ease, transform 150ms ease; }
.skip-btn:hover:not(:disabled) { background: #e7e0f0; border-color: #c9bddc; transform: translateY(-1px); }
.skip-btn:active:not(:disabled) { transform: translateY(1px); }
.skip-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ===== Backspace key ===== */
.backspace-key { display: flex; align-items: center; justify-content: center; padding: 0; min-width: 0; min-height: 0; height: 100%; box-sizing: border-box; }
.backspace-key svg { display: block; width: 18px; height: 18px; max-width: 100%; max-height: 100%; flex: 0 0 auto; }

/* ===== Tablet and mobile ===== */
@media (max-width: 540px) {
  #app { padding: 7px 8px; }
  .brand-icon { font-size: 1.55rem; }
  .brand h1 { font-size: 1.35rem; }
  .brand p { font-size: .7rem; }
  .scoreboard { gap: 6px; margin-bottom: 7px; }
  .team-panel { padding: 5px 6px; column-gap: 4px; row-gap: 3px; }
  .team-name { font-size: .76rem; gap: 3px; }
  .team-name span:first-child { font-size: .95rem; }
  .score { font-size: 1.35rem; }
  .time-label { font-size: .55rem; letter-spacing: 0; }
  .clock { font-size: .85rem; }
  .versus-badge { padding: 6px; font-size: .65rem; }
  .turn-banner { padding: 6px 8px; font-size: .88rem; margin-bottom: 7px; }
  .play-card { padding: 9px; }
  .sentence { justify-content: center; gap: 4px; margin: 8px 0 6px; }
  .char-tile { min-width: 43px; min-height: 66px; padding: 4px 5px; gap: 3px; font-size: 1.9rem; }
  .char-tile .tile-pin { font-size: .68rem; }
  .instruction { font-size: .8rem; margin-bottom: 7px; }
  .answer-row { flex-wrap: wrap; gap: 6px; }
  .answer-box { flex: 0 0 112px; width: 112px; min-width: 112px; }
  #ok-btn { flex-basis: 100px; width: 100px; min-width: 100px; height: 50px; min-height: 50px; padding: 7px 8px; font-size: .98rem; }
  .skip-btn { height: 50px; min-height: 50px; padding: 7px 10px; font-size: .82rem; }
  .feedback { flex: 1 1 100%; min-height: 20px; margin-top: 2px; font-size: .78rem; text-align: center; }
  .keyboard { gap: 4px; margin-top: 7px; }
  .key { min-height: 34px; font-size: .88rem; }
}

@media (max-width: 360px) {
  .char-tile { min-width: 35px; min-height: 58px; font-size: 1.6rem; }
  .char-tile .tile-pin { font-size: .62rem; }
  .key { min-height: 32px; }
  .answer-row { gap: 4px; }
  .answer-box { flex-basis: 108px; width: 108px; min-width: 108px; }
  #clear-btn { padding: 7px 6px; font-size: .8rem; }
  #ok-btn { flex-basis: 88px; width: 88px; min-width: 88px; height: 40px; min-height: 40px; padding: 6px 5px; font-size: .9rem; }
  .skip-btn { height: 40px; min-height: 40px; padding: 6px 8px; font-size: .78rem; }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

/* Secret Easter egg: dragon icon in setup */ #toggle-team-names { cursor: inherit; user-select: none; }
