/* Sum Cut — Playnesta shell stylesheet (MIT).
   No fonts, images or network assets: the board is a grid of paper cells with
   a target rail on the right and at the bottom. */

:root {
  --bg: #111621;
  --bg-2: #18202e;
  --bg-3: #202a3b;
  --line: #2e3a4f;
  --paper: #f2eee3;
  --paper-2: #e9e3d3;
  --paper-3: #d8d1bd;
  --grid: #b9b09b;
  --ink: #f2f5fa;
  --ink-2: #b9c4d6;
  --ink-3: #7f8ca3;
  --board-ink: #2a2f3a;
  --accent: #4fc3b0;
  --accent-2: #e0a458;
  --good: #6fd39a;
  --bad: #e5796a;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, #1b2434 0%, var(--bg) 72%);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body { overflow: hidden; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: calc(var(--pn-vh, 1vh) * 100);
  min-height: 0;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-height: 32px;
}
.title { font-size: 14px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.title small { color: var(--ink-3); font-weight: 500; margin-left: 4px; font-size: 11px; }
.spacer { flex: 1 1 auto; }
.hud { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-2); white-space: nowrap; }
.hud b { color: var(--ink); font-variant-numeric: tabular-nums; }
.hud .opt { color: var(--ink-3); margin-left: 4px; }

/* ------------------------------------------------------------------ main */
#main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  min-height: 0;
  overflow: hidden;
}

#board {
  position: relative;
  width: 320px;
  height: 320px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n, 5), 1fr) var(--tg, 1fr);
  grid-template-rows: repeat(var(--n, 5), 1fr) var(--tg, 1fr);
  gap: 2px;
  padding: 3px;
  background: var(--grid);
  border: 2px solid var(--grid);
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .38), inset 0 0 0 2px rgba(255, 255, 255, .35);
  overflow: hidden;
}

/* ------------------------------------------------------------------ cells */
.cell {
  position: relative;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--board-ink);
  font: inherit;
  font-size: var(--cell-font, 16px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: background .1s ease, color .1s ease, opacity .1s ease;
}
.cell:hover { background: #fbf8ef; }
.cell.cut {
  background: var(--paper-3);
  color: rgba(42, 47, 58, .38);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  box-shadow: inset 0 0 0 2px rgba(42, 47, 58, .12);
}
.cell.cut:hover { background: #cfc7b0; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------------------------------------------------------------- targets */
.target {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--bg-3);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  border: 1px solid var(--line);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.target b { font-size: var(--target-font, 13px); color: var(--ink); }
.target small { font-size: var(--small-font, 9px); color: var(--ink-3); }
.target.over { border-color: rgba(224, 164, 88, .55); }
.target.over b { color: var(--accent-2); }
.target.under { border-color: rgba(127, 140, 163, .55); }
.target.done { background: rgba(111, 211, 154, .18); border-color: rgba(111, 211, 154, .6); }
.target.done b { color: var(--good); }
#grid.compact .target small { display: none; }
.target.row { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.target.col { border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; }
.corner {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-2);
  color: var(--ink-3);
  font-size: var(--small-font, 9px);
  letter-spacing: .04em;
  border-radius: 0 0 6px 0;
}

/* ------------------------------------------------------------------- won */
#won {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
}
#won span {
  font-size: calc(var(--cell, 32px) * 2.2);
  color: var(--good);
  text-shadow: 0 4px 18px rgba(0, 0, 0, .55);
  animation: pop .28s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: scale(.6); }
  to { opacity: 1; transform: scale(1); }
}
.hidden { display: none !important; }

/* -------------------------------------------------------------- statusbar */
#statusbar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px 10px 8px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}
#status {
  font-size: 11.5px;
  color: var(--ink-2);
  min-height: 15px;
  line-height: 1.25;
}
#status[data-tone="good"] { color: var(--good); }
#status[data-tone="bad"] { color: var(--bad); }
#status[data-tone="warm"] { color: var(--accent-2); }

.actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink);
  border-radius: 6px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1;
  min-height: 26px;
  padding: 0 9px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: #2a3548; border-color: #3c4a63; }
.btn:active { transform: translateY(1px); }
.btn.icon { padding: 0 8px; font-size: 14px; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d201d;
  font-weight: 700;
  min-height: 32px;
  padding: 0 16px;
  font-size: 13px;
}
.puzzle-no {
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
  white-space: nowrap;
}

/* -------------------------------------------------------------- win card */
#win {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9, 12, 18, .62);
  z-index: 20;
}
.win-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px 16px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .55);
  text-align: center;
  min-width: 232px;
  animation: pop .22s ease-out;
}
.win-label {
  font-size: 15px;
  font-weight: 800;
  color: var(--good);
  margin-bottom: 12px;
}
.win-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-bottom: 14px;
}
.win-body div { display: flex; flex-direction: column; gap: 2px; }
.win-body span { font-size: 10px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.win-body b { font-size: 14px; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- modal */
#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(9, 12, 18, .66);
  z-index: 30;
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  max-width: 460px;
  max-height: 100%;
  overflow: auto;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .55);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-2);
}
.modal-card h2 { margin: 0 0 8px; font-size: 16px; color: var(--ink); }
.modal-card p { margin: 0 0 10px; }
.modal-card ol { margin: 0 0 10px; padding-left: 18px; }
.modal-card li { margin-bottom: 5px; }
.modal-card b { color: var(--ink); }
.modal-card .muted { color: var(--ink-3); font-size: 11.5px; }
.modal-card .btn { margin-top: 4px; }

/* ----------------------------------------------------------------- toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translate(-50%, 8px);
  background: rgba(24, 32, 46, .96);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 40;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------- compact */
@media (max-height: 430px) {
  .topbar { min-height: 28px; padding: 4px 8px; }
  #statusbar { padding: 4px 8px 6px; gap: 3px; }
  #status { font-size: 10.5px; min-height: 13px; }
  .btn { min-height: 24px; font-size: 11px; padding: 0 8px; }
}
