/* Fitdoku prototype styling.
   Loosely follows docs/art-audio.md: warm neutral board, ink digits, calm palette,
   colour is never the only signal for a conflict (a corner wedge backs the red). */

:root {
  --bg: #f4efe6;
  --board-bg: #fbf8f2;
  --ink: #2b2620;
  --line-thin: #d8cfbe;
  --line-heavy: #4a4335;
  --given-bg: #eae2d0;
  --given-ink: #2b2620;
  --piece-bg: #dce8e4;
  --piece-border: #6f9c8f;
  --piece-selected-bg: #bfe0d6;
  --piece-selected-border: #2f7a67;
  --conflict-bg: #f7d3d0;
  --conflict-ink: #8a1f1a;
  --conflict-border: #c0392b;
  --success: #2f7a4f;
  --disabled: #b9b2a2;
  --shadow: 0 2px 6px rgba(0,0,0,0.18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 8px 8px 0;
}

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 10px;
}

#brand {
  font-weight: 700;
  font-size: 18px;
  margin-right: auto;
}
#brand .tag {
  font-weight: 400;
  font-size: 11px;
  color: #8a8271;
  border: 1px solid var(--line-thin);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: middle;
}

#puzzle-picker-wrap {
  font-size: 12px;
  color: #635c4d;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  order: 3;
}
#puzzle-picker {
  font-size: 13px;
  padding: 3px 4px;
  flex: 1;
}

#hud {
  display: flex;
  gap: 10px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

#clock {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  min-width: 84px;
  text-align: right;
}

#conflict-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--conflict-ink);
  background: var(--conflict-bg);
  border: 1px solid var(--conflict-border);
  border-radius: 999px;
  padding: 2px 9px;
}

#hints-used {
  font-size: 11px;
  color: #8a8271;
}

.hidden { display: none !important; }

/* ---------- board ---------- */

#board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

#board {
  --n: 9;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  width: min(100%, 420px);
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border: 3px solid var(--line-heavy);
  border-radius: 6px;
  box-shadow: var(--shadow);
  position: relative;
  user-select: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line-thin);
  border-bottom: 1px solid var(--line-thin);
  font-size: clamp(14px, 4vw, 22px);
  font-weight: 600;
  color: var(--ink);
  transition: background-color 120ms ease;
}

/* heavy box borders every 3rd (or sqrt(n)th) line, added dynamically via classes */
.cell.box-right { border-right: 2px solid var(--line-heavy); }
.cell.box-bottom { border-bottom: 2px solid var(--line-heavy); }
.cell.edge-right { border-right: none; }
.cell.edge-bottom { border-bottom: none; }

.cell.given {
  background: var(--given-bg);
  color: var(--given-ink);
  font-weight: 800;
}

.cell.placed {
  background: var(--piece-bg);
  cursor: pointer;
}

.cell.conflict {
  background: var(--conflict-bg);
  color: var(--conflict-ink);
}

/* redundant non-colour conflict marker: a corner wedge, per art-audio.md */
.cell.conflict::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  border-style: solid;
  border-width: 0 40% 40% 0;
  border-color: transparent var(--conflict-border) transparent transparent;
}

.cell.drop-target-ok { outline: 2px solid var(--piece-selected-border); outline-offset: -2px; }
.cell.drop-target-bad { outline: 2px solid var(--conflict-border); outline-offset: -2px; }

#full-not-solved-banner {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--conflict-ink);
  background: var(--conflict-bg);
  border: 1px solid var(--conflict-border);
  border-radius: 6px;
  padding: 6px 12px;
}

/* ---------- tray ---------- */

#tray-wrap {
  margin-top: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 2px 10px;
  -webkit-overflow-scrolling: touch;
}

#tray {
  display: flex;
  gap: 10px;
  min-height: 76px;
  align-items: center;
  padding: 0 4px;
}

.piece-tile {
  flex: 0 0 auto;
  display: grid;
  gap: 1px;
  background: var(--piece-border);
  border: 2px solid var(--piece-border);
  border-radius: 6px;
  padding: 2px;
  cursor: grab;
  box-shadow: var(--shadow);
  touch-action: none;
}

.piece-tile.selected {
  border-color: var(--piece-selected-border);
  box-shadow: 0 0 0 3px rgba(47,122,103,0.35), var(--shadow);
}

.piece-tile.unplaceable {
  opacity: 0.4;
  filter: grayscale(0.6);
}

.piece-tile .pc {
  width: 26px;
  height: 26px;
  background: var(--piece-selected-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  border-radius: 2px;
}
.piece-tile .pc.empty { background: transparent; }

/* piece currently being dragged, rendered as a floating clone */
#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  opacity: 0.9;
  transform: scale(1.4);
  transform-origin: top left;
}

/* ---------- action bar ---------- */

#actionbar {
  display: flex;
  gap: 8px;
  padding: 10px 4px 14px;
  margin-top: auto;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 60%, rgba(244,239,230,0));
}

#actionbar button {
  flex: 1;
  padding: 12px 6px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--line-heavy);
  border-radius: 8px;
  background: var(--board-bg);
  color: var(--ink);
  position: relative;
  overflow: hidden;
}
#actionbar button:disabled {
  color: var(--disabled);
  border-color: var(--line-thin);
}
#actionbar button:active:not(:disabled) { transform: translateY(1px); }

#btn-hint { display: flex; align-items: center; justify-content: center; gap: 6px; }
#hint-cooldown-ring {
  width: 16px; height: 16px;
  transform: rotate(-90deg);
}
#hint-cooldown-ring circle {
  fill: none;
  stroke: var(--piece-selected-border);
  stroke-width: 4;
  stroke-dasharray: 100.5;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 200ms linear;
}
#hint-cooldown-ring.hidden { display: none; }

/* ---------- win overlay ---------- */

#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43,38,32,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#win-card {
  background: var(--board-bg);
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
  max-width: 320px;
}
#win-card h1 { margin: 0 0 8px; color: var(--success); }
#win-card p { margin: 4px 0; font-size: 15px; }
#win-card button {
  margin-top: 16px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
  border: none;
  background: var(--success);
  color: white;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--line-heavy);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
}
