/* Tiles — Popsicle design system */
:root {
  --ground: #f6f5fa;
  --surface: #ffffff;
  --surface2: #efedf8;
  --border: #e2def0;
  --ink: #241f33;
  --muted: #6f6885;
  --accent: #e2570e;
  --accent-ink: #ffffff;
  --teal: #0a9d90;
  --grape: #6b4de6;
  --danger: #d64545;
  --gold: #e0a400;
  --shadow: 0 6px 20px rgba(36, 31, 51, 0.10);
  --tile-shadow: 0 3px 10px rgba(36, 31, 51, 0.18), 0 1px 3px rgba(36, 31, 51, 0.12);
  --glass: rgba(255, 255, 255, 0.72);
  --radius: 15px;
}
:root[data-theme="dark"] {
  --ground: #191625;
  --surface: #241f33;
  --surface2: #2e2840;
  --border: #3b3352;
  --ink: #f2eef9;
  --muted: #a69dba;
  --accent: #ff8a3d;
  --accent-ink: #2a1206;
  --teal: #2fd4c4;
  --grape: #ab8dff;
  --danger: #ff6b78;
  --gold: #e0b24d;
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.42);
  --tile-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  --glass: rgba(25, 22, 37, 0.72);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", "Nunito", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 10px)
    calc(env(safe-area-inset-bottom) + 6px) calc(env(safe-area-inset-left) + 10px);
  gap: 6px;
}

/* ---- top bar ---- */
#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 7px; min-width: 0; }
.brand-icon { width: 30px; height: 30px; border-radius: 8px; box-shadow: var(--tile-shadow); }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.hud { display: flex; gap: 4px; margin-left: auto; }
.hud-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
}
.hud-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.hud-num { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
#hud-combo.hot { color: var(--accent); }
.top-actions { display: flex; align-items: center; gap: 6px; }

.seg {
  display: inline-flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  cursor: pointer;
}
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* ---- board ---- */
#board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  position: relative;
}
#board { display: grid; gap: var(--gap, 8px); }
.tile {
  position: relative;
  width: var(--ts, 90px);
  height: var(--ts, 90px);
  border-radius: max(10px, calc(var(--ts, 90px) * 0.12));
  background-size: cover;
  background-position: center;
  box-shadow: var(--tile-shadow);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.25s ease;
}
.tile::after {
  /* subtle bevel to sell physical depth */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -2px 4px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}
.tile.sel {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 0 0 3px var(--accent), 0 10px 22px rgba(0, 0, 0, 0.3);
  z-index: 2;
}
.tile.empty {
  cursor: default;
  filter: saturate(0.65) brightness(0.92);
}
.tile.empty::after {
  box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.28), inset 0 -1px 0 rgba(255, 255, 255, 0.25);
}
.tile.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.layer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.layer.ring { width: 94%; height: 94%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)); }
.layer.medal { width: 56%; height: 56%; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4)); }
.layer.center { width: 32%; height: 32%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45)); }
.layer.pop { animation: pop 0.45s ease forwards; }
@keyframes pop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  60% { opacity: 1; transform: translate(-50%, -58%) scale(1.22); }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(1.35); }
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
}
.hint .free { color: var(--teal); }

/* ---- bottom bar ---- */
#botbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mode-seg button { padding: 6px 13px; font-size: 13px; }
.palette-row { display: flex; gap: 6px; margin-left: auto; }
.pal-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s;
}
.pal-dot.active { border-color: var(--accent); transform: scale(1.12); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.pill-btn {
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.pill-btn:active { transform: translateY(1px); }
.pill-btn.subtle { background: var(--surface2); color: var(--ink); border: 1px solid var(--border); box-shadow: none; }

/* ---- modal ---- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 30, 0.45);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 18px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(460px, 100%);
  max-height: min(82dvh, 640px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
}
.modal-head h2 { font-size: 18px; font-weight: 800; }
.modal-close { margin-left: auto; }
.modal-body { padding: 4px 16px 16px; overflow-y: auto; font-size: 14px; line-height: 1.5; }
.modal-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin: 14px 0 6px; }
.modal-body details { border: 1px solid var(--border); border-radius: 12px; margin: 8px 0; background: var(--surface2); }
.modal-body summary { padding: 10px 12px; font-weight: 700; cursor: pointer; font-size: 14px; }
.modal-body details > div { padding: 2px 12px 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.stat-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 8px; text-align: center; }
.stat-card b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-card span { font-size: 11px; color: var(--muted); }
.field-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; flex-wrap: wrap; }
.field-row label { font-size: 13px; color: var(--muted); min-width: 72px; }
.field-row input, .field-row select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 9px;
}
.win-splash { text-align: center; padding: 8px 0 4px; }
.win-splash .big { font-size: 42px; }
.win-splash h2 { font-size: 22px; margin: 4px 0 10px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 74px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--ground);
  border-radius: 999px;
  padding: 9px 17px;
  font-size: 13px;
  font-weight: 600;
  z-index: 99;
  box-shadow: var(--shadow);
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
[hidden] { display: none !important; }

/* narrow phones: tighten chrome */
@media (max-width: 430px) {
  .brand-name { display: none; }
  .hud-stat { min-width: 46px; padding: 3px 6px; }
  #botbar { gap: 6px; }
  .pill-btn { padding: 8px 11px; }
}
