/* 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: hidden; 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:disabled { opacity: 0.35; }
.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; line-height: 1.4; }

.diff-grid { display: flex; flex-direction: column; gap: 10px; }
.diff-opt { display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-radius: 14px; text-align: left;
  background: rgba(255,255,255,0.06); border: 1px solid var(--card-border); color: var(--text); }
.diff-opt .d-name { font-size: 1.1rem; font-weight: 800; }
.diff-opt small { color: var(--muted); font-size: 0.82rem; }
.diff-opt.active { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }
.diff-opt:active { transform: scale(0.98); }
.stats-mini { display: flex; justify-content: center; gap: 16px; color: var(--muted); font-size: 0.85rem; }

/* Game header */
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: 0 0 auto; }
.len-pill { font-size: 0.85rem; color: var(--muted); background: var(--card); border: 1px solid var(--card-border);
  padding: 6px 12px; border-radius: 999px; }
.len-pill strong { color: var(--text); }
.btn-menu { padding: 12px 13px; font-size: 1.2rem; line-height: 1; letter-spacing: 1px; }

/* Board */
.board-wrap { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; padding: 10px 0 6px; }
.board { position: relative; }
.mtile {
  position: absolute; width: var(--tile); height: var(--tile);
  border-radius: calc(var(--tile) * 0.2);
  display: grid; place-items: center; line-height: 1;
  font-size: calc(var(--tile) * 0.56);
  background: linear-gradient(180deg, #fdfdff, #dfe4f0);
  border: 1px solid rgba(10,14,25,0.35);
  box-shadow: 0 2px 0 rgba(10,14,25,0.45), 0 4px 8px rgba(0,0,0,0.32);
  transition: transform 0.1s ease, filter 0.2s ease;
  animation: tileIn 0.24s ease-out both;
}
@keyframes tileIn { from { opacity: 0; transform: scale(0.86); } to { opacity: 1; transform: none; } }
/* Covered tiles keep their shape but drop back so the free ones pop. */
.mtile.locked { background: linear-gradient(180deg, #b9c0d0, #97a0b4); }
.mtile.locked::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: rgba(6,9,18,0.42);
}
.mtile.free { cursor: pointer; }
.mtile.free:active { transform: scale(0.92); }
.mtile.flying { pointer-events: none; margin: 0; }
.mtile.spin { animation: spin 0.4s ease both; }
@keyframes spin { 50% { transform: rotateY(90deg) scale(0.9); } to { transform: none; } }
.mtile.nudge { animation: nudge 0.32s ease; }
@keyframes nudge { 25% { transform: translateX(-3px); } 60% { transform: translateX(3px); } to { transform: none; } }
.mtile.called { animation: called 0.45s ease both; }
@keyframes called { 0%, 100% { box-shadow: 0 2px 0 rgba(10,14,25,0.45), 0 4px 8px rgba(0,0,0,0.32); }
  50% { box-shadow: 0 0 0 4px var(--gold), 0 0 22px var(--gold); } }

/* Tile bar */
.bar { flex: 0 0 auto; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  background: rgba(4,7,15,0.35); border: 1px solid var(--card-border);
  border-radius: 16px; padding: 8px; }
.bslot { aspect-ratio: 1 / 1; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255,255,255,0.06); font-size: clamp(1rem, 5.2vw, 1.6rem); line-height: 1; }
.bslot.filled { background: linear-gradient(180deg, #fdfdff, #dfe4f0);
  box-shadow: 0 2px 0 rgba(10,14,25,0.4); animation: chipIn 0.18s ease-out both; }
@keyframes chipIn { from { transform: scale(0.55); opacity: 0.2; } to { transform: none; opacity: 1; } }
.bslot.matched { animation: chipPop 0.3s ease-in both; }
@keyframes chipPop { 40% { transform: scale(1.16); } to { transform: scale(0.2); opacity: 0; } }
.bar.danger { border-color: var(--bad); box-shadow: 0 0 0 2px color-mix(in srgb, var(--bad) 35%, transparent); }

/* Power buttons */
.powers { flex: 0 0 auto; display: flex; justify-content: center; gap: 26px; margin-top: 14px; }
.power { position: relative; width: 62px; height: 62px; border-radius: 50%;
  background: linear-gradient(165deg, #ffd34a, #f0a41f); color: #3a2500;
  font-size: 1.55rem; display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.38); transition: transform 0.1s ease, opacity 0.15s ease; }
.power:active { transform: scale(0.94); }
.power:disabled { opacity: 0.35; }
.p-icon { line-height: 1; }
.p-badge { position: absolute; top: -3px; right: -3px; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px; background: var(--bg-2); border: 2px solid #f0a41f; color: var(--text);
  font-size: 0.74rem; font-weight: 800; display: grid; place-items: center; }

.toast { position: absolute; top: 56px; 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: 15; }
.toast.show { opacity: 0.96; }

/* Overlays */
.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; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.menu-actions { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.menu-item {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 14px;
  text-align: left; background: rgba(255,255,255,0.05); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 14px; color: var(--text); text-decoration: none;
  transition: transform 0.1s ease, background 0.15s ease;
}
.menu-item:active { transform: scale(0.98); background: rgba(255,255,255,0.09); }
.menu-item .m-icon { grid-row: 1 / 3; font-size: 1.6rem; }
.menu-item .m-title { font-weight: 700; font-size: 1.05rem; }
.menu-item small { color: var(--muted); font-size: 0.8rem; }
.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; }

.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; }
}
