:root {
  --bg: #0f1b2d;
  --panel: #182a45;
  --tile: #f4e3b1;
  --tile-text: #2b2412;
  --accent: #ffb300;
  --good: #3ddc84;
  --bad: #ff5c5c;
  --text: #eaf0fa;
  --muted: #8fa3c2;
  --tile-size: 72px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1c3358, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.app { max-width: 520px; margin: 0 auto; padding: 16px; }
.screen { display: none; text-align: center; }
.screen.active { display: block; }
.hidden { display: none !important; }

.logo { font-size: 3rem; margin: 24px 0 8px; letter-spacing: 1px; }
.logo span { color: var(--accent); }
.logo.small { font-size: 2.2rem; }
.tag { color: var(--muted); margin: 0 0 24px; }
.loading { color: var(--muted); padding: 24px; }

.levels { display: grid; gap: 12px; }
.level {
  border: 0; border-radius: 14px; padding: 18px; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  transition: transform .1s, filter .1s;
}
.level strong { font-size: 1.4rem; }
.level small { opacity: .85; }
.level:hover { transform: translateY(-2px); filter: brightness(1.1); }
.level.easy { background: #2e9e5b; }
.level.medium { background: #d98a00; }
.level.hard { background: #c0392b; }
.best { color: var(--muted); font-size: .9rem; margin-top: 20px; white-space: pre-line; }

.hud { display: flex; gap: 8px; margin-bottom: 8px; }
.stat { flex: 1; background: var(--panel); border-radius: 10px; padding: 6px; }
.stat span { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.stat b { font-size: 1.4rem; }
.stat.low b { color: var(--bad); }

.current {
  height: 40px; line-height: 40px; font-size: 1.8rem; font-weight: 700;
  letter-spacing: 3px; text-transform: uppercase;
}
.current.ok { color: var(--good); }
.current.dup { color: var(--accent); }
.current.bad { color: var(--bad); }

.board {
  display: grid; gap: 6px; justify-content: center; margin: 4px auto 0;
  touch-action: none; padding: 10px; background: var(--panel); border-radius: 16px;
  width: fit-content; position: relative;
}
.tile {
  width: var(--tile-size); height: var(--tile-size);
  display: flex; align-items: center; justify-content: center;
  background: var(--tile); color: var(--tile-text);
  font-size: calc(var(--tile-size) * .5); font-weight: 800;
  border-radius: 12px; box-shadow: 0 3px 0 #b9a465; text-transform: uppercase;
  transition: background .08s, transform .08s;
}
.tile.sel { background: var(--accent); transform: scale(.94); box-shadow: 0 1px 0 #b27b00; }
.tile.ok { background: var(--good); }
.tile.bad { background: var(--bad); }

.board.spin { transform: rotate(90deg); transition: transform .25s ease; }
.rotate-btn { margin-top: 10px; padding: 8px 18px; }

.msg { height: 26px; margin: 8px 0; color: var(--muted); }
.msg.good { color: var(--good); }
.msg.warn { color: var(--accent); }

.found-wrap { text-align: left; }
.found-wrap h2, h3 { font-size: .85rem; color: var(--muted); text-transform: uppercase; margin: 8px 0; }
.found { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; max-height: 160px; overflow-y: auto; }
.found li { background: var(--panel); border-radius: 8px; padding: 4px 10px; font-size: .95rem; text-transform: lowercase; }
.found li em { font-style: normal; color: var(--accent); margin-left: 6px; font-size: .8rem; }
.missed { max-height: 320px; justify-content: center; }
.missed li { color: var(--muted); }

.link-btn { background: none; border: 0; color: var(--muted); margin-top: 12px; cursor: pointer; text-decoration: underline; }

.final { margin: 12px 0; }
.final span { font-size: 4rem; font-weight: 800; color: var(--accent); display: block; line-height: 1; }
.final small { color: var(--muted); }
.end-actions { display: flex; gap: 10px; justify-content: center; margin: 16px 0 24px; }
.primary, .secondary { border: 0; border-radius: 10px; padding: 12px 22px; font-size: 1rem; cursor: pointer; font-weight: 600; }
.primary { background: var(--accent); color: #1b1300; }
.secondary { background: var(--panel); color: var(--text); }

@media (max-width: 440px) {
  :root { --tile-size: 58px; }
}
@media (max-width: 440px) {
  .board.size5 { --tile-size: 50px; }
}
