@import url("../theme.css");
@import url("../chrome.css");

:root {
  --topbar: 56px;
  /* This bar has more buttons (Clear/Choose/⚙/🔊), so shrink them a touch. */
  --tb-gap: 10px;
  --btn-pad: 8px 12px;
  --btn-font: 15px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- Top bar (header chrome is shared in ../chrome.css) ---------- */
.btn:focus-visible,
.swatch:focus-visible,
.choice:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- Play area: canvas + palette (orientation aware) ---------- */
.stage {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  min-width: 0;
  padding: 10px;
  gap: 10px;
}
.paper {
  flex: 1 1 auto;
  position: relative;       /* origin for the absolutely-placed canvas + zoom controls */
  overflow: hidden;         /* clip the canvas when it's zoomed in */
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--shadow);
  min-height: 0;
  min-width: 0;
}
/* The canvas holds the line-art PNG. zoom.js drives its size/position with a
   CSS transform (translate + scale), so it's pinned to the paper's top-left and
   transformed from there. */
.canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  cursor: crosshair;
  touch-action: none;
}

/* Loading spinner shown while a picture's pixels are being fetched/decoded. */
.loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.loader[hidden] { display: none; }
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid var(--shadow);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Floating zoom controls (bottom-right of the paper). */
.zoom-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 6px;
  z-index: 3;
}
.zoom-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  color: var(--primary);
  font-size: 22px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}
.zoom-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.zoom-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Crayon palette: a fixed 2-line grid (orientation decides whether those two
   lines are columns or rows) so the box always sits on the RIGHT (landscape,
   2 columns) or the BOTTOM (portrait, 2 rows). */
.palette {
  flex: 0 0 auto;
  display: grid;
  gap: clamp(6px, 1.4vw, 12px);
  align-content: center;
  justify-content: center;
  padding: clamp(6px, 1.4vw, 12px);
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--shadow);
}
.swatch {
  width: clamp(30px, 6vmin, 48px);
  height: clamp(30px, 6vmin, 48px);
  border-radius: 50%;
  border: 3px solid #00000018;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform .1s;
}
.swatch:active { transform: translateY(2px); }
.swatch.selected {
  outline: 4px solid var(--primary);
  outline-offset: 2px;
  transform: scale(1.1);
  box-shadow: 0 4px 0 var(--shadow);
}

@media (orientation: landscape) {
  .stage { flex-direction: row; }
  /* 2 columns, fill top-to-bottom then across */
  .palette { grid-auto-flow: row; grid-template-columns: repeat(2, auto); overflow-y: auto; }
}
@media (orientation: portrait) {
  .stage { flex-direction: column; }
  /* 2 rows, fill left-to-right then down */
  .palette { grid-auto-flow: column; grid-template-rows: repeat(2, auto); overflow-x: auto; }
}

/* ---------- Picture picker overlay ---------- */
.screen {
  position: fixed;
  inset: 0;
  background: #0008;
  display: none;
  padding: 16px;
  z-index: 10;
  overflow: auto;
}
.screen.show { display: flex; }
.screen-card {
  position: relative;
  margin: auto;
  background: #fff;
  border-radius: 28px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 10px 0 #0004;
  max-width: 560px;
  width: 100%;
  animation: pop .3s ease;
}
.start-card { display: flex; flex-direction: column; max-height: 90vh; }
.screen-close {
  position: absolute;
  top: 8px;
  right: 12px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: bold;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 50%;
}
.screen-close:active { background: rgba(0,0,0,.08); }
.screen-title { color: var(--primary); margin: 0 0 12px; font-size: clamp(26px, 6vw, 42px); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Reuse the Memory deck-picker grid look. */
.pick-choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}
.pick-choices.scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; align-content: start; padding: 4px; }
.choice {
  font-family: inherit;
  cursor: pointer;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #FBEFE2;
  color: var(--ink);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.choice:active { transform: translateY(2px); }
.choice .choice-icons { font-size: 34px; line-height: 1; }
.choice .choice-sub { font-size: 13px; color: var(--ink-soft); }
