/* Paper-and-ink look: warm graph paper, black outlines, a few printed colors.
   The canvas uses the same colors (js/constants.js). */
:root {
  --paper: #efe9dd;
  --sheet: #fbf8f1;
  --white: #fffdf8;
  --ink: #26231f;
  --ink-soft: #625b51;
  --rule: #d8d0c1;
  --grid: rgba(42, 122, 112, 0.09);
  --grid-major: rgba(42, 122, 112, 0.2);
  --red: #d4462a;
  --teal: #2a7a70;
  --mustard: #e3a524;
  --blue: #33589f;
  --highlight: rgba(227, 165, 36, 0.3);

  --serif: "Young Serif", Georgia, serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

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

html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: var(--sans);
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--serif); font-weight: 400; letter-spacing: -0.01em; }

/* Buttons sit on a 2px ink "ledge" and press down into it */
button {
  font: inherit;
  font-weight: 500;
  color: inherit;
  cursor: pointer;
  background: var(--sheet);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--ink);
  transition: transform 0.06s, box-shadow 0.06s, background 0.15s;
}
button:hover { background: var(--white); }
button:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
button:disabled { opacity: 0.55; cursor: progress; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.primary { background: var(--ink); color: var(--sheet); padding: 9px 18px; font-weight: 600; }
.primary:hover { background: #3b3731; }
.secondary { padding: 8px 14px; }
kbd {
  font-family: var(--mono);
  font-size: 0.72em;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
  opacity: 0.7;
}
.label {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

#app { max-width: 1000px; margin: 0 auto; padding: 0 16px 24px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 12px;
  flex-wrap: wrap;
}
.level-info { flex: 1; min-width: 200px; }
.level-info h1 { margin: 0; font-size: 1.6rem; line-height: 1.15; }
.level-info .num {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--red);
  vertical-align: 0.3em;
  margin-right: 8px;
}
.level-info .num:empty { display: none; }
.level-info p { margin: 3px 0 0; color: var(--ink-soft); font-size: 0.95rem; }
.hud { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { height: 38px; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.icon-btn {
  width: 38px; height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-weight: 600;
  font-size: 1.05rem;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path:first-child { fill: currentColor; }
#muteBtn .sound-off, #muteBtn[aria-pressed="true"] .sound-on { display: none; }
#muteBtn[aria-pressed="true"] .sound-off { display: inline; }
#camBtn.on { background: var(--teal); color: var(--white); }
#camBtn.on::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }
.readout {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  min-width: 96px;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.readout::before { content: "Time"; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }

/* ---------- stage: a sheet of graph paper ---------- */
#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
  background:
    linear-gradient(var(--grid-major) 1px, transparent 1px) -1px -1px / 120px 120px,
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px) -1px -1px / 120px 120px,
    linear-gradient(var(--grid) 1px, transparent 1px) -1px -1px / 24px 24px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) -1px -1px / 24px 24px,
    var(--sheet);
}
#video, #world {
  position: absolute;
  inset: 0;
  width: 100% !important;  /* Matter sets inline px sizes; keep it responsive */
  height: 100% !important;
}
/* Mirrored, and printed onto the paper like a faded photocopy */
#video {
  transform: scaleX(-1);
  object-fit: cover;
  opacity: 0;
  filter: grayscale(1) contrast(1.1);
  mix-blend-mode: multiply;
  transition: opacity 0.4s;
}
#video.live { opacity: 0.45; }
#world { touch-action: none; cursor: grab; }
#world.holding { cursor: grabbing; }
#world.pointing { cursor: pointer; }
#world.denied { cursor: not-allowed; }

.stage-pill {
  position: absolute;
  left: 10px; top: 10px;
  background: var(--sheet);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.85rem;
  pointer-events: none;
}
.stage-status {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--sheet);
  border-radius: 4px;
  padding: 1px 8px;
  pointer-events: none;
}
.stage-status:empty { display: none; }
.toast {
  position: absolute;
  left: 50%;
  top: 72px;
  transform: translate(-50%, -8px);
  background: var(--ink);
  color: var(--sheet);
  padding: 10px 16px;
  border-radius: 6px;
  max-width: calc(100% - 32px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.below { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding-top: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
#spawnBar { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.tip { margin: 0; color: var(--ink-soft); flex: 1; min-width: 220px; }
.tip::before {
  content: "Tip";
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
  margin-right: 8px;
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(38, 35, 31, 0.5);
  overflow-y: auto;
  animation: fade 0.15s;
}
@keyframes fade { from { opacity: 0; } }
.card {
  background: var(--sheet);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 26px;
  width: 100%;
  max-width: 560px;
  margin: auto;
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.card.wide { max-width: 820px; }
.card.center { text-align: center; }
.card h2 { margin: 0 0 10px; font-size: 1.7rem; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; margin-bottom: 0; }
.big { font-family: var(--mono); font-size: 1.7rem; font-weight: 500; margin: 4px 0; }

.hero { display: flex; gap: 18px; align-items: center; }
.logo { width: 68px; height: 68px; flex: none; overflow: visible; }
.logo * { stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.hero h1 { margin: 0; font-size: 2.4rem; line-height: 1.05; }
.hero p { margin: 6px 0 0; color: var(--ink-soft); }
.start-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 20px 0 6px; }
.card.center .start-row { justify-content: center; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0 12px;
  padding-top: 16px;
  border-top: 1.5px solid var(--ink);
}
.section-head h2 { margin: 0; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.level-card {
  text-align: left;
  padding: 14px 14px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  align-items: start;
}
.level-card .lc-num {
  grid-row: span 3;
  font-family: var(--mono);
  font-size: 1.5rem;
  color: var(--red);
  line-height: 1.1;
}
.level-card .lc-name { font-family: var(--serif); font-size: 1.1rem; font-weight: 400; }
.level-card .lc-goal { font-size: 0.82rem; color: var(--ink-soft); font-weight: 400; }
.level-card .lc-stars {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.level-card .lc-stars small { margin-left: 8px; font-size: inherit; }

.star { width: 1em; height: 1em; fill: none; stroke: #c3b9a6; stroke-width: 1.6; stroke-linejoin: round; }
.star.on { fill: var(--mustard); stroke: var(--ink); }
.lc-stars .star { width: 16px; height: 16px; }
.stars { display: flex; justify-content: center; gap: 6px; margin: 8px 0 2px; }
.stars .star { width: 46px; height: 46px; animation: starPop 0.35s backwards; }
.stars .star:nth-child(2) { animation-delay: 0.12s; }
.stars .star:nth-child(3) { animation-delay: 0.24s; }
@keyframes starPop { from { transform: scale(0.3) rotate(-40deg); opacity: 0; } }

.steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 6px 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.steps li {
  counter-increment: step;
  border: 1.5px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.steps li::before {
  content: counter(step, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--red);
}
.steps b { display: block; color: var(--ink); font-weight: 600; }
.tips { color: var(--ink-soft); padding-left: 18px; margin: 0 0 18px; line-height: 1.65; font-size: 0.92rem; }

/* ---------- leaderboard ---------- */
.board { border-top: 1.5px solid var(--ink); margin-top: 16px; padding-top: 12px; text-align: left; }
.board h3 { margin: 0 0 4px; }
.board-list { list-style: none; margin: 0; padding: 0; }
.board-list li {
  display: grid;
  grid-template-columns: 2em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--rule);
}
.board-list li:last-child { border-bottom: none; }
.board-list li.me { background: var(--highlight); }
.board-list li.empty { display: block; color: var(--ink-soft); padding: 12px 6px; }
.board-list .rank { font-family: var(--mono); color: var(--ink-soft); }
.board-list li:first-child .rank { color: var(--red); }
.board-list .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.board-list .time { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.board .small { margin-top: 8px; }
.name-form { display: flex; gap: 8px; margin-top: 10px; }
.name-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: var(--white);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
}
.name-form input::placeholder { color: #9b9384; }
#boards .card { max-width: 640px; }
#boards .board-list { margin-top: 8px; min-height: 13em; }
.tabs { display: flex; gap: 2px 18px; flex-wrap: wrap; border-bottom: 1.5px solid var(--rule); margin-top: 14px; }
.tab {
  border: none;
  border-bottom: 2.5px solid transparent;
  border-radius: 0;
  box-shadow: none;
  background: none;
  padding: 8px 0;
  margin-bottom: -1.5px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.tab:hover { background: none; color: var(--ink); }
.tab:active { transform: none; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red); font-weight: 600; }
.tab-num { font-family: var(--mono); font-size: 0.8em; color: var(--red); margin-right: 5px; font-weight: 400; }

/* ---------- small screens ---------- */
@media (max-width: 600px) {
  #app { padding: 0 10px 14px; }
  .topbar { gap: 10px; }
  .level-info { min-width: 0; flex-basis: calc(100% - 90px); }
  .level-info h1 { font-size: 1.25rem; }
  .level-info p { font-size: 0.85rem; }
  .hud { width: 100%; }
  .readout { min-width: 0; margin-right: auto; }
  .hero { gap: 14px; }
  .logo { width: 52px; height: 52px; }
  .hero h1 { font-size: 1.8rem; }
  .card { padding: 18px; box-shadow: 4px 4px 0 var(--ink); }
  .steps { grid-template-columns: 1fr; }
  .stage-status { top: 34px; font-size: 0.8rem; }
  .start-row button { flex: 1; }
  .tab:not([aria-selected="true"]) .tab-name { display: none; }
}
