:root {
  color-scheme: dark;
  --bg: #111113;
  --panel: #18171c;
  --panel2: #212027;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e6e3ea;
  --muted: #8f8b99;
  --accent: #b4505f;
  --accent-h: #c35c6b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: clamp(12px, 0.9vw + 8px, 14px)/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.01em; }
.lvl { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.lvl b { color: var(--text); }
.stats { display: flex; gap: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats b { color: var(--text); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn, .icon {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font: inherit;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn { padding: 6px 12px; }
.btn:hover, .icon:hover { background: #2a2831; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--accent-h); }
.btn[aria-pressed="true"] { border-color: var(--accent); color: #f1dadf; }
.btn:disabled, .icon:disabled { opacity: 0.35; cursor: default; }
.icon { width: 26px; height: 26px; padding: 0; line-height: 1; font-size: 16px; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 34px; padding: 0; }

.stage { position: relative; min-height: 0; }
#board:focus { outline: none; }
#board { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

.tray { fill: rgba(255, 255, 255, 0.022); stroke: rgba(255, 255, 255, 0.06); stroke-width: 1; }
.outline { fill: #19181d; stroke: rgba(255, 255, 255, 0.2); stroke-width: 2; stroke-linejoin: round; }
.slot { fill: none; stroke: transparent; stroke-width: 1.2; stroke-dasharray: 5 5; pointer-events: none; }
.guide .slot { stroke: rgba(255, 255, 255, 0.17); }
.piece polygon { stroke: #111113; stroke-width: 1.6; stroke-linejoin: round; cursor: grab; }
.piece.drag polygon { cursor: grabbing; }
.piece.placed polygon { cursor: default; }
.piece.sel polygon { stroke: rgba(230, 227, 234, 0.9); stroke-width: 2.2; }

.win {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 24px);
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}
.win-title { font-weight: 700; font-size: 16px; }
.win-sub { color: var(--muted); font-variant-numeric: tabular-nums; }
.win-btns { display: flex; gap: 8px; }

.foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.rot { display: flex; gap: 6px; }
.tip { flex: 1; color: var(--muted); font-size: 13px; }
.link { appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

@media (max-width: 640px), (max-height: 520px) {
  .bar { padding: 6px 10px; gap: 4px 10px; }
  .brand { gap: 10px; }
  .brand h1 { font-size: 15px; }
  .stats { gap: 10px; }
  .actions { gap: 6px; }
  .actions .btn { padding: 4px 9px; }
  .tip { display: none; }
  .foot { padding: 5px 10px; gap: 8px; justify-content: space-between; }
  .icon-btn { width: 34px; height: 28px; }
}
@media (max-width: 420px) {
  .stats span:nth-child(3) { display: none; }
}
