/* Nut Sort: pegboard workbench theme */

:root {
  --board: #2c4756;
  --board-dark: #1f3541;
  --hole: #21394a;
  --paper: #eaeff2;
  --ink: #1c2a33;
  --ink-2: #4a5f6b;
  --line: #b3c1ca;
  --brass: #d9a441;
  --brass-hi: #f0c86e;
  --brass-lo: #96691c;
  --danger: #a4241c;
  --focus: #ffd25e;
  --text: #f2f6f8;
  --text-2: #b9ccd6;
  --metal-lo: #8b96a2;
  --metal-hi: #e8edf2;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-size: 18px; -webkit-text-size-adjust: 100%; }
html, body { height: 100%; margin: 0; }

body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background-color: var(--board);
  background-image: radial-gradient(circle at center, var(--hole) 0 3px, transparent 3.6px);
  background-size: 28px 28px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { height: 100vh; height: 100dvh; }

.screen { display: flex; flex-direction: column; height: 100%; }
.screen.centered { overflow: auto; padding: 16px; }
.screen.centered > * { margin: auto; }

h1, h2, p { margin: 0; }
button, input { font: inherit; }

.loading-text { font-size: 1.2rem; color: var(--text-2); }

/* ---------- Buttons ---------- */
.btn {
  min-height: 3rem;
  padding: 0 1.2rem;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .12);
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; border-color: rgba(255, 255, 255, .22); }
.btn.wide { width: 100%; }
.btn.primary {
  background: linear-gradient(var(--brass-hi), var(--brass));
  border-color: var(--brass-lo);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--brass-lo);
}
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--brass-lo); transform: translateY(2px); }
.card .btn:not(.primary), .sheet .btn:not(.primary) {
  background: #fff; color: var(--ink); border-color: var(--line);
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Log in card ---------- */
.card {
  width: min(430px, 100%);
  background: var(--paper);
  color: var(--ink);
  border-radius: 22px;
  padding: 26px 24px 28px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .4), inset 0 2px 0 #fff;
}
.title { text-align: center; font-size: 2.3rem; font-weight: 900; letter-spacing: .01em; line-height: 1.1; }
.tagline { text-align: center; color: var(--ink-2); margin: 6px 0 18px; line-height: 1.35; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: #d5dee4; padding: 4px; border-radius: 14px; margin-bottom: 16px;
}
.tabs button {
  min-height: 2.8rem; border: 0; border-radius: 10px; background: transparent;
  color: var(--ink-2); font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.tabs button[aria-selected="true"] {
  background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .2), inset 0 -3px 0 var(--brass);
}

label { display: block; font-weight: 700; margin: 12px 0 5px; }
input[type="text"], input[type="password"] {
  width: 100%; height: 3.1rem; padding: 0 14px;
  border: 2px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); font-size: 1.1rem;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--brass-lo); outline: 3px solid rgba(217, 164, 65, .45); }
label.check { display: flex; align-items: center; font-weight: 600; margin: 12px 0 4px; cursor: pointer; }
label.check.big { font-size: 1.05rem; margin-top: 18px; }
input[type="checkbox"] { width: 1.4rem; height: 1.4rem; accent-color: var(--brass-lo); flex: none; margin: 0 10px 0 0; }

.help { color: var(--ink-2); font-size: .88rem; line-height: 1.4; margin-top: 8px; }
.error { color: var(--danger); font-weight: 700; min-height: 1.4em; margin: 10px 0 12px; line-height: 1.35; }

/* ---------- Shared nut look ---------- */
.nut, .bn {
  position: relative;
  border-radius: 30%/40%;
  background: var(--c, #888);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .4), inset 0 -3px 0 rgba(0, 0, 0, .22), inset 0 2px 0 rgba(255, 255, 255, .4);
}
.nut::before, .bn::before {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(90deg,
    rgba(0, 0, 0, .32) 0, rgba(0, 0, 0, .06) 7%,
    rgba(255, 255, 255, .26) 7%, rgba(255, 255, 255, .26) 30%,
    rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0) 68%,
    rgba(0, 0, 0, .14) 68%, rgba(0, 0, 0, .14) 93%,
    rgba(0, 0, 0, .34) 93%);
}

/* little decorative bolts on the log in card and win sheet */
.brand, .win-bolt { display: flex; justify-content: center; margin-bottom: 8px; }
.brand-bolt, .win-bolt { position: relative; }
.brand-bolt { display: flex; flex-direction: column-reverse; align-items: center; width: 64px; height: 74px; padding-bottom: 5px; }
.win-bolt { flex-direction: column-reverse; align-items: center; width: 64px; height: 74px; margin: 0 auto 10px; padding-bottom: 5px; }
.brand-bolt::before, .win-bolt::before {
  content: ""; position: absolute; bottom: 0; left: 50%; width: 12px; height: 100%;
  transform: translateX(-50%); border-radius: 6px 6px 2px 2px;
  background: linear-gradient(90deg, var(--metal-lo), var(--metal-hi) 45%, var(--metal-lo));
}
.brand-bolt::after, .win-bolt::after {
  content: ""; position: absolute; bottom: 0; left: 50%; width: 60px; height: 6px; transform: translateX(-50%);
  border-radius: 4px; background: linear-gradient(#5b6774, #39434e);
}
.bn { width: 50px; height: 16px; margin-top: 2px; z-index: 1; }
.bn.b1 { --c: #e5383b; }
.bn.b2 { --c: #2f5bd8; }
.bn.b3 { --c: #f7d63a; }

/* ---------- Game screen ---------- */
.topbar {
  display: flex; align-items: center;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(24, 40, 50, .94);
  border-bottom: 2px solid rgba(0, 0, 0, .3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
}
.topbar > * + * { margin-left: 12px; }
.lvl { flex: 1; min-width: 0; }
#level-label { font-size: 1.6rem; font-weight: 900; line-height: 1.1; }
.note { font-size: .8rem; color: var(--text-2); line-height: 1.25; margin-top: 2px; }
.right { text-align: right; }
.moves { font-weight: 800; font-size: 1.05rem; }
.save-status { font-size: .78rem; min-height: 1.1em; color: var(--text-2); }
.save-status[data-state="saved"] { color: #9fe3b0; }
.save-status[data-state="offline"] { color: #ffd06b; font-weight: 800; }

#board-wrap {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; padding: 10px 12px;
}
.board {
  margin: auto;
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--col-w, 70px));
  gap: var(--row-gap, 18px) 10px;
  justify-content: center;
}

.bolt {
  position: relative;
  width: var(--col-w); height: var(--bolt-h);
  padding: 0; border: 0; background: none; color: inherit;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  cursor: pointer; touch-action: manipulation;
}
.bolt::before { /* highlight ring */
  content: ""; position: absolute; top: -5px; right: -3px; bottom: -2px; left: -3px; border-radius: 14px;
  border: 3px solid transparent; pointer-events: none;
}
.bolt.sel::before { border-color: #fff; background: rgba(255, 255, 255, .08); }
.bolt.hint-from::before { border-color: #7fe0a5; border-style: solid; background: rgba(127, 224, 165, .1); }
.bolt.hint-to::before { border-color: var(--focus); border-style: dashed; background: rgba(255, 210, 94, .1); }
.bolt:focus-visible { outline: none; }
.bolt:focus-visible::before { border-color: var(--focus); }
.bolt.done { cursor: default; }

.rod {
  position: absolute; bottom: var(--base-h); left: 50%;
  width: calc(var(--nut-w) * .24);
  height: calc(var(--nut-h) * (var(--cap) + .45) + 4px);
  transform: translateX(-50%);
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(90deg, var(--metal-lo), var(--metal-hi) 45%, var(--metal-lo));
}
.base {
  position: absolute; bottom: 0; left: 50%; width: 94%; height: var(--base-h);
  transform: translateX(-50%); border-radius: 8px;
  background: linear-gradient(#5f6b78, #38424d);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .4);
}
.stack {
  position: relative;
  display: flex; flex-direction: column-reverse; align-items: center;
  margin-bottom: var(--base-h);
}

.nut { width: var(--nut-w); height: var(--nut-h); margin-top: 2px; transition: transform .14s ease; }
.bolt.sel .nut.top {
  transform: translateY(calc(var(--nut-h) * -.9));
  filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .45));
}
.nut.drop { animation: drop .2s ease-out; }
@keyframes drop {
  from { transform: translateY(calc(var(--nut-h) * -1.1)); }
  to   { transform: none; }
}
.nut.hidden-nut { --c: #58646f; --ink-nut: #e8eef2; }

.num {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: none; place-items: center; z-index: 1;
  font-weight: 900; line-height: 1; font-size: calc(var(--nut-h) * .62);
  color: var(--ink-nut, #fff);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .25);
  pointer-events: none;
}
body.show-numbers .num { display: grid; }
.nut.hidden-nut .num { display: grid; }

.bolt.done .rod { background: linear-gradient(90deg, var(--brass-lo), var(--brass-hi) 45%, var(--brass-lo)); }
.bolt.done .base { background: linear-gradient(var(--brass-hi), var(--brass-lo)); }
.bolt.done::after { /* finished badge in the space above the bolt */
  content: "✓"; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 1.5rem; height: 1.5rem; display: grid; place-items: center;
  border-radius: 50%; background: var(--brass); color: var(--ink); font-weight: 900; font-size: .95rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

.controls {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(24, 40, 50, .94);
  border-top: 2px solid rgba(0, 0, 0, .3);
}
.controls .btn { min-height: 3.3rem; font-size: 1.1rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(6.4rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 420px); padding: 12px 18px; border-radius: 12px; text-align: center;
  background: var(--paper); color: var(--ink); font-weight: 700; line-height: 1.35;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .4);
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10; padding: 16px; overflow: auto;
  display: flex; background: rgba(12, 24, 31, .74);
}
.sheet {
  margin: auto; width: min(420px, 100%);
  background: var(--paper); color: var(--ink);
  border-radius: 20px; padding: 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5), inset 0 2px 0 #fff;
  animation: pop .22s ease-out;
}
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 1.35rem; font-weight: 900; line-height: 1.25; }
.sheet-actions { display: grid; gap: 10px; margin-top: 20px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 0; }
.stats div { background: #fff; border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); }
.stats dt { font-size: .8rem; color: var(--ink-2); }
.stats dd { margin: 2px 0 0; font-size: 1.4rem; font-weight: 900; }
.win-sheet { text-align: center; }
.win-sheet h2 { font-size: 1.7rem; }
.win-sheet p { margin: 6px 0 20px; color: var(--ink-2); font-size: 1.05rem; }

@media (max-width: 380px) {
  html { font-size: 17px; }
  .topbar { padding-left: 10px; padding-right: 10px; }
  .topbar > * + * { margin-left: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
