/* Design tokens + theme palettes live in /css/themes.css (shared site-wide). */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 80% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 55%),
    var(--bg);
  overflow: hidden; user-select: none; -webkit-user-select: none;
}
#app { height: 100%; position: relative; }
.screen { position: absolute; inset: 0; padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bottom) + 14px);
  display: flex; flex-direction: column; overflow-y: auto; animation: fadeIn 0.28s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Buttons */
button { font-family: inherit; cursor: pointer; border: none; color: var(--text); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-size: 1.15rem; font-weight: 700; padding: 16px; border-radius: 14px; width: 100%;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent); transition: transform 0.12s ease, opacity 0.15s ease; }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost { background: transparent; border: 1px solid var(--card-border); color: var(--muted);
  padding: 10px 14px; border-radius: 12px; font-size: 0.9rem; font-weight: 600; }
.btn-ghost:active { background: rgba(255,255,255,0.05); }

/* Setup */
.setup-wrap { max-width: 460px; width: 100%; margin: auto; display: flex; flex-direction: column; gap: 16px; }
.back-link { align-self: flex-start; color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; padding: 4px 2px; }
.back-link:active { color: var(--text); }
.brand { text-align: center; padding: 4px 0; }
.brand-mark { font-size: 3rem; line-height: 1; filter: drop-shadow(0 6px 14px color-mix(in srgb, var(--accent) 50%, transparent)); }
.brand h1 { font-size: 2.4rem; margin: 6px 0 0; letter-spacing: -1px; font-weight: 800;
  background: linear-gradient(135deg, var(--text), var(--accent)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tagline { color: var(--muted); margin: 2px 0 0; font-size: 0.95rem; }
.card { background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 16px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 12px 2px 0; text-align: center; }

.len-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.len-opt { aspect-ratio: 1 / 1; border-radius: 14px; font-size: 1.8rem; font-weight: 800;
  background: rgba(255,255,255,0.06); border: 1px solid var(--card-border); color: var(--text); }
.len-opt.active { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }
.len-opt:active { transform: scale(0.95); }

.stats-mini { display: flex; justify-content: center; gap: 16px; color: var(--muted); font-size: 0.85rem; }

/* Game */
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.len-pill { font-size: 0.85rem; color: var(--muted); background: var(--card); border: 1px solid var(--card-border);
  padding: 6px 12px; border-radius: 999px; }

.grid-wrap { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; padding: 12px 0; }
.grid { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 7px;
  width: 100%; max-width: calc(var(--cols) * 62px); }
.tile { aspect-ratio: 1 / 1; display: grid; place-items: center; border-radius: 9px;
  border: 2px solid var(--card-border); font-size: clamp(1.4rem, 7vw, 2.1rem); font-weight: 800; text-transform: uppercase;
  color: var(--text); }
.tile.active { border-color: var(--muted); animation: pop 0.1s ease; }
@keyframes pop { from { transform: scale(0.9); } to { transform: scale(1); } }
.tile.filled { color: #fff; border-color: transparent; }
.tile.correct { background: var(--good); color: #06231a; }
.tile.present { background: var(--gold); color: #3a2b00; }
.tile.absent { background: rgba(140,150,170,0.26); color: var(--text); }
.tile.flip { animation: flip 0.5s ease; }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
.tile.shake { animation: shake 0.4s; }
@keyframes shake { 10%,90% { transform: translateX(-2px); } 30%,70% { transform: translateX(-5px); } 50% { transform: translateX(5px); } }

.toast { position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 0.85rem;
  padding: 9px 16px; border-radius: 10px; opacity: 0; transition: opacity 0.2s ease; pointer-events: none; z-index: 5; }
.toast.show { opacity: 0.96; }

/* Keyboard */
.keyboard { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key { flex: 1; height: 52px; max-width: 42px; border-radius: 8px; font-size: 1rem; font-weight: 700;
  background: rgba(255,255,255,0.14); color: var(--text); display: grid; place-items: center; }
.key.wide { max-width: 62px; font-size: 0.75rem; }
.key:active { transform: scale(0.94); }
.key.correct { background: var(--good); color: #06231a; }
.key.present { background: var(--gold); color: #3a2b00; }
.key.absent { background: rgba(255,255,255,0.05); color: var(--muted); }

.btn-send {
  width: 100%; margin-top: 10px; padding: 16px; border-radius: 14px;
  font-size: 1.2rem; font-weight: 800; letter-spacing: 0.3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.12s ease;
}
.btn-send:active { transform: scale(0.97); }

/* Result overlay */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end;
  background: rgba(4,7,15,0); transition: background 0.22s ease; }
.overlay.open { background: rgba(4,7,15,0.6); backdrop-filter: blur(3px); }
.sheet { width: 100%; max-height: 92%; background: var(--bg-2); border-top-left-radius: 24px; border-top-right-radius: 24px;
  padding: 12px 18px calc(var(--safe-bottom) + 18px); border-top: 1px solid var(--card-border);
  transform: translateY(100%); transition: transform 0.24s cubic-bezier(0.2,0.8,0.2,1);
  display: flex; flex-direction: column; overflow-y: auto; text-align: center; }
.overlay.open .sheet { transform: translateY(0); }
.sheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 3px; background: var(--muted); opacity: 0.5; margin: 2px auto 10px; }
.result-emoji { font-size: 3.4rem; animation: bounce 0.5s cubic-bezier(0.2,1.4,0.4,1) both; }
@keyframes bounce { from { transform: scale(0); } to { transform: scale(1); } }
.sheet h2 { margin: 4px 0 0; font-size: 1.8rem; }
.result-sub { color: var(--text); margin: 6px 0 14px; }
.result-sub strong { color: var(--accent); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 1.7rem; font-weight: 800; }
.stat-lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.dist-title { font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.dist { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.dist-row { display: flex; align-items: center; gap: 8px; }
.dist-g { width: 14px; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.dist-bar { background: rgba(255,255,255,0.14); color: var(--text); text-align: right; padding: 3px 8px;
  border-radius: 5px; font-size: 0.8rem; font-weight: 700; min-width: 24px; }
.dist-bar.hot { background: var(--good); color: #06231a; }

.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn-ghost, .sheet-actions .btn-primary { width: auto; flex: 1; }

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