*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1923;
  --surface: #1a2535;
  --surface2: #223040;
  --accent: #3ecfcf;
  --text: #e8f0f7;
  --muted: #7a9ab5;
  --border: #2a3f55;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --card-radius: 14px;

  /* rarity */
  --r1: #94a3b8;
  --r2: #4ade80;
  --r3: #38bdf8;
  --r4: #c084fc;
  --r5: #fbbf24;
}

html, body { min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
}

a { color: inherit; }

/* ── Top bar ───────────────────────────────────────────────────── */
header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
}
.brand .globe { font-size: 1.4rem; }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stats { display: flex; gap: 16px; font-size: 0.95rem; color: var(--muted); }
.stats b { color: var(--text); }

.limit {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.limit select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(120deg, var(--accent), #2ea8a8);
  color: #06262b;
  border: none;
}

/* ── Main ──────────────────────────────────────────────────────── */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.intro { text-align: center; color: var(--muted); font-size: 0.95rem; line-height: 1.5; }
.intro b { color: var(--text); }

.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.chip.wrong { color: var(--bad); }

/* ── Hyper Easy tray ───────────────────────────────────────────── */
.tray-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tray-wrap[hidden] { display: none; }
.tray { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tray:empty::after { content: "All placed!"; color: var(--muted); font-size: 0.9rem; padding: 4px; }
.tray-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.tray-chip:hover { border-color: var(--accent); }
.tray-chip.sel {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface2));
  border-color: var(--accent);
  transform: translateY(-1px);
}
.tray-chip:disabled { opacity: 0.5; cursor: default; }
.tray-chip img { width: 22px; border-radius: 2px; }
.tray-msg { font-size: 0.88rem; line-height: 1.5; text-align: center; }
.tray-msg:empty { display: none; }
.tray-msg.warn { color: var(--warn); }
.tray-msg.bad .ok { color: var(--good); }
.tray-msg.bad .no { color: var(--bad); }
.tray-msg span { display: inline-block; margin: 0 6px; }
.cell.empty.target { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.cell.empty.target .plus { color: var(--accent); }
.cell.shake { animation: shake 0.35s; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 12%, transparent);
}
.chip.r1 { color: var(--r1); }
.chip.r2 { color: var(--r2); }
.chip.r3 { color: var(--r3); }
.chip.r4 { color: var(--r4); }
.chip.r5 { color: var(--r5); }

/* ── Grid ──────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.corner {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.head {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  text-align: center;
  cursor: help;
  min-height: 84px;
}
.head.row { min-height: 0; }
.head-icon { font-size: 1.4rem; line-height: 1; }
.head-label { font-size: 0.8rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.head-info {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.12s, background 0.15s;
}
.cell.empty:hover { border-color: var(--accent); transform: translateY(-2px); }
.cell .plus { font-size: 2rem; color: var(--border); font-weight: 300; transition: color 0.15s; }
.cell.empty:hover .plus { color: var(--accent); }

.cell.filled {
  --rc: var(--r1);
  border-color: var(--rc);
  background: color-mix(in srgb, var(--rc) 14%, var(--surface));
  cursor: default;
}
.cell.filled.r2 { --rc: var(--r2); }
.cell.filled.r3 { --rc: var(--r3); }
.cell.filled.r4 { --rc: var(--r4); }
.cell.filled.r5 { --rc: var(--r5); box-shadow: 0 0 18px color-mix(in srgb, var(--r5) 35%, transparent); }
.cell.filled img { width: 52%; max-width: 64px; flex-shrink: 0; border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,0.4); }
.cell-name {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.cell-name.long { font-size: 0.66rem; }
.cell-pts { flex-shrink: 0; }
.cell-pts { font-size: 0.72rem; font-weight: 800; color: var(--rc); }
.cell-count {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.62rem;
  color: var(--muted);
}

.cell.missed { border-style: dashed; background: transparent; }
.cell.missed:hover { border-color: var(--accent); }
.cell-reveal { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.cell-sub { font-size: 0.68rem; color: var(--muted); opacity: 0.7; }

/* After the game, every square opens its answer list. */
.grid.over .cell { cursor: pointer; }
.grid.over .cell:hover { border-color: var(--accent); }

.cell.pop { animation: pop 0.45s ease; }
@keyframes pop {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ── End bar ───────────────────────────────────────────────────── */
.endbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.endbar[hidden] { display: none; }
.end-score { font-size: 2.4rem; font-weight: 800; color: var(--accent); }
.end-score small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.endbar p { color: var(--muted); font-size: 0.92rem; }

/* ── Dialogs ───────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, 0.7);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 16px;
  z-index: 50;
}
.overlay[hidden] { display: none; }

.dialog {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 18px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dialog.shake { animation: shake 0.35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.close:hover { color: var(--text); }

.dialog-crit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-right: 24px;
}
.crit {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 0.9rem;
}
.amp { color: var(--muted); font-weight: 700; }

#guessInput {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1.05rem;
  outline: none;
}
#guessInput:focus { border-color: var(--accent); }

.feedback { font-size: 0.88rem; line-height: 1.5; min-height: 0; }
.feedback:empty { display: none; }
.feedback.bad { color: var(--text); }
.feedback.warn { color: var(--warn); }
.feedback span { display: block; }
.feedback .ok { color: var(--good); }
.feedback .no { color: var(--bad); }

.suggestions, .answers { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.suggestions:empty { display: none; }
.suggestions li, .answers li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.95rem;
}
.suggestions li { cursor: pointer; }
.suggestions li.sel, .suggestions li:hover { background: var(--surface2); }
.suggestions li.used { opacity: 0.45; }
.suggestions li .used-tag { margin-left: auto; color: var(--muted); }
small.sov { color: var(--muted); font-size: 0.72rem; font-weight: 400; margin-left: 4px; }
.suggestions img, .answers img { width: 28px; border-radius: 2px; flex-shrink: 0; }

.answers-count { color: var(--muted); font-size: 0.85rem; }
.answers li { background: var(--bg); }
.answers li.mine { outline: 2px solid var(--accent); }
.a-name { flex: 1; min-width: 0; }
.a-name small { color: var(--accent); font-size: 0.72rem; margin-left: 4px; }
.answers li:not(.mine) .a-name small { color: var(--muted); }

/* ── Tooltip ───────────────────────────────────────────────────── */
.tip {
  position: absolute;
  z-index: 40;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.tip b { color: var(--text); }
.tip[hidden] { display: none; }

/* ── Small screens ─────────────────────────────────────────────── */
@media (max-width: 560px) {
  header.topbar { padding: 12px 16px; }
  .stats { gap: 12px; font-size: 0.85rem; }
  .grid { gap: 5px; }
  .head { padding: 4px 2px; min-height: 70px; }
  .head-icon { font-size: 1.1rem; }
  .head-label { font-size: 0.64rem; }
  .cell { border-radius: 10px; padding: 3px; }
  .cell-name { font-size: 0.6rem; }
  .cell-name.long { font-size: 0.5rem; }
  .cell-name { -webkit-line-clamp: 2; line-clamp: 2; flex-shrink: 0; }
  .cell.filled img { width: 42%; }
  .cell-pts { font-size: 0.6rem; }
  .cell .plus { font-size: 1.5rem; }
  .cell-reveal { font-size: 0.64rem; }
  .cell-sub { display: none; }
  .intro { font-size: 0.88rem; }
}
