/* Main menu, leaderboard and waiting room, in the "Bureau" look: a sheet of graph paper on the
   desk where doodled creeps march through a pencil maze, a tabbed notebook, sticky notes, a rubber
   stamp and polaroids. Shared tokens (--paper, --ink, --red, ...) come from style.css. */

:root {
  --pink: #ffc8dd;
  --sky: #bde0fe;
  --mint: #caf0c4;
  --graphite: rgba(55, 62, 84, 0.36);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .1 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* living background: graph paper, pencil maze, marching creeps */
.doodle-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background-color: var(--paper);
  background-image: var(--grain), linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 180px 180px, 24px 24px, 24px 24px;
}
body:has(#game:not(.hidden)) .doodle-bg { display: none; }
.doodle-bg svg { width: 100%; height: 100%; display: block; opacity: 0.55; }
.doodle-bg .towers { fill: rgba(255, 255, 255, 0.55); stroke: var(--graphite); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.doodle-bg .route { fill: none; stroke: rgba(215, 38, 61, 0.22); stroke-width: 3; stroke-dasharray: 2 12; stroke-linecap: round; animation: march 1.6s linear infinite; }
.doodle-bg .shots { stroke: var(--red); stroke-width: 2; stroke-dasharray: 4 5; opacity: 0; animation: pew 5s steps(1) infinite; }
.doodle-bg .shots path:nth-child(2) { animation-delay: 1.3s; }
.doodle-bg .shots path:nth-child(3) { animation-delay: 2.6s; }
.doodle-bg .creep, .hero-doodle .creep-row { stroke: var(--ink); stroke-width: 1.6; }
.doodle-bg .eye, .hero-doodle .eye, .polaroid .eye { fill: var(--ink); stroke: none; }
.doodle-bg .creeps-still { display: none; }
@keyframes march { to { stroke-dashoffset: -28; } }
@keyframes pew { 0%, 88% { opacity: 0; } 90%, 96% { opacity: 0.8; } }
.doodle-bg .shots path { animation: inherit; }

.menu-screen {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 14px;
  min-height: 100dvh; padding: max(16px, env(safe-area-inset-top)) 16px 28px;
}
.menu-screen :focus-visible { outline: 3px dashed var(--red); outline-offset: 3px; }

/* hero: logo slot, hand-drawn title, doodled scene, links slot */
#menu { padding-bottom: calc(118px + env(safe-area-inset-bottom)); }
.menu-hero { position: relative; width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.menu-links:empty { display: none; }
/* The logo is a taped paper card (icons/logo.svg); the h1 keeps its text as the image's alt. */
.menu-title { line-height: 0; }
.menu-logo {
  display: block; width: clamp(180px, 52vw, 240px); height: auto; rotate: -2deg;
  filter: drop-shadow(2px 5px 6px rgba(60, 40, 0, 0.25)); animation: logo-in 0.45s ease-out both;
}
@keyframes logo-in { from { opacity: 0; translate: 0 -12px; rotate: -6deg; } }
.menu-subtitle {
  margin: 4px 0 0; font-family: var(--script); font-size: 1.35rem; line-height: 1.15; color: var(--ink);
  background: linear-gradient(transparent 58%, rgba(255, 241, 118, 0.85) 58% 92%, transparent 92%);
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.hero-doodle { display: none; width: 100%; max-width: 480px; overflow: visible; }
.hero-doodle .pencil { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.hero-doodle .barrel { stroke-width: 7; }
.hero-doodle .shot { fill: none; stroke: var(--red); stroke-width: 2.5; stroke-dasharray: 6 6; animation: march 0.9s linear infinite; }
.hero-doodle .boom { fill: var(--sticky); stroke: var(--red); stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: boom 1.8s ease-in-out infinite; }
.hero-doodle .creep-row { animation: shuffle 2.4s ease-in-out infinite alternate; }
.hero-doodle .arrow { fill: none; stroke: var(--red); stroke-width: 2; stroke-linecap: round; }
.hero-doodle .note { font-family: var(--script); font-size: 22px; font-weight: 700; fill: var(--red); }
@keyframes boom { 50% { scale: 1.18; rotate: 8deg; } }
@keyframes shuffle { to { translate: 14px 0; } }
.menu-links { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 1.1rem; }
.menu-links a, .pencil-link { color: var(--ink); text-decoration: underline wavy var(--red); text-underline-offset: 4px; }
.pencil-link { padding: 4px 2px; border: none; background: none; font-size: 1.3rem; }
.pencil-link:hover:not(:disabled) { background: none; color: var(--red); }
.menu-corner { position: absolute; top: 4px; right: 0; display: flex; gap: 8px; }
.menu-corner .lang-toggle { transform: rotate(3deg); background: var(--paper-2); }
.menu-corner .docs-link { background: var(--paper-2); transform: rotate(-2deg); }
.install-app { font-family: var(--marker); padding: 3px 10px; background: var(--sticky); transform: rotate(-2deg); }

/* notebook: name note, tabs, lined page */
.notebook-wrap { position: relative; width: 100%; display: flex; flex-direction: column; --tab: var(--sticky); }
.notebook-wrap:has(.tab-rooms.active) { --tab: var(--pink); }
.notebook-wrap:has(.tab-ranks.active) { --tab: var(--sky); }
.menu-name { align-self: flex-start; width: min(300px, 88%); padding: 12px 16px; margin: 10px 0 14px 6px; z-index: 2; }
.menu-name label { flex-direction: row; align-items: baseline; gap: 10px; color: var(--ink); }
.menu-name label span { flex: none; font-family: var(--script); font-size: 1.4rem; font-weight: 700; }
.menu-name input { font-size: 1.35rem; padding-top: 2px; min-width: 0; }
.menu-tabs { display: flex; gap: 4px; padding-left: 12px; position: relative; z-index: 1; }
.menu-tab {
  min-height: 44px; padding: 6px 14px 8px; border: 1.5px solid var(--ink); border-bottom: none; border-radius: 10px 10px 0 0;
  font-family: var(--marker); font-size: 1rem; translate: 0 6px; transition: translate 0.15s ease;
}
.menu-tab.tab-play { background: var(--sticky); }
.menu-tab.tab-rooms { background: var(--pink); }
.menu-tab.tab-ranks { background: var(--sky); }
.menu-tab:hover:not(:disabled) { translate: 0 2px; filter: brightness(1.04); }
.menu-tab.tab-play:hover:not(:disabled) { background: var(--sticky); }
.menu-tab.tab-rooms:hover:not(:disabled) { background: var(--pink); }
.menu-tab.tab-ranks:hover:not(:disabled) { background: var(--sky); }
.menu-tab.active { translate: 0 1px; box-shadow: 0 -3px 0 inset rgba(0, 0, 0, 0.06); }
.notebook-page {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 18px 16px 22px 40px;
  border-top: 7px solid var(--tab); background-color: #fff;
  background-image: var(--grain), linear-gradient(90deg, transparent 28px, rgba(215, 38, 61, 0.45) 28px 30px, transparent 30px),
    repeating-linear-gradient(transparent 0 27px, rgba(70, 130, 200, 0.26) 27px 28px);
  background-size: 180px 180px, 100% 100%, 100% 100%;
  box-shadow: 3px 10px 22px rgba(60, 40, 0, 0.28), 0 1px 0 rgba(0, 0, 0, 0.08);
  border-radius: 2px 6px 6px 2px;
}
.notebook-page::before {
  content: ""; position: absolute; left: 6px; top: 14px; bottom: 14px; width: 14px;
  background: radial-gradient(circle at 7px 9px, #c9c3b4 0 4px, var(--ink-soft) 4px 5px, transparent 5.5px) 0 0 / 14px 26px repeat-y;
}
.notebook-page > .error:empty { display: none; }
.notebook-page > .error { font-size: 1.1rem; padding: 4px 10px; background: var(--highlight); align-self: flex-start; transform: rotate(-1deg); }
.menu-panel { display: flex; flex-direction: column; gap: 14px; animation: page-in 0.25s ease-out; }
@keyframes page-in { from { opacity: 0; } }
.menu-heading { margin: 0; font-family: var(--script); font-weight: 700; font-size: 2.1rem; line-height: 1; color: var(--red); }
.panel-intro { margin: 0; font-size: 1.1rem; line-height: 1.3; }

/* mode sticky notes */
.mode-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mode-chips.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mode-chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 10px 12px; border-style: dashed; background: var(--paper-2); min-height: 84px;
}
.mode-chip strong { font-size: 1.25rem; }
.mode-chip small { line-height: 1.2; }
.mode-chip.active { border-style: solid; border-color: var(--red); background: var(--highlight); box-shadow: 2px 3px 0 var(--ink); }
.mode-glyph { display: none; }
.mode-chips.compact .mode-chip { min-height: 0; }
.mode-chips.compact .mode-chip small { display: none; }

.mode-notes { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 2px 4px; }
.mode-notes .mode-chip {
  position: relative; display: grid; grid-template-columns: 48px minmax(0, 1fr); column-gap: 12px; align-items: center;
  min-height: 62px; padding: 10px 40px 10px 12px; border: none; border-radius: 1px 1px 12px 1px;
  box-shadow: 1px 4px 8px rgba(60, 40, 0, 0.22); rotate: -1deg; transition: rotate 0.15s ease, translate 0.15s ease;
}
.mode-notes .mode-chip:nth-child(1) { background: var(--sticky); }
.mode-notes .mode-chip:nth-child(2) { background: var(--pink); rotate: 1.2deg; }
.mode-notes .mode-chip:nth-child(3) { background: var(--mint); rotate: -0.6deg; }
.mode-notes .mode-chip:hover:not(:disabled) { translate: 0 -2px; rotate: 0deg; }
.mode-notes .mode-chip:nth-child(1):hover { background: var(--sticky); }
.mode-notes .mode-chip:nth-child(2):hover { background: var(--pink); }
.mode-notes .mode-chip:nth-child(3):hover { background: var(--mint); }
.mode-notes .mode-glyph { display: block; grid-row: 1 / 3; }
.mode-notes .mode-glyph svg { width: 48px; height: 32px; display: block; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.mode-notes .mode-chip small { color: #3d4569; }
.mode-notes .mode-chip:not(.active) small { display: none; }
.mode-notes .mode-chip.active { rotate: 0deg; box-shadow: 0 0 0 2.5px var(--red), 2px 5px 0 var(--ink); }
.mode-notes .mode-chip.active::after {
  content: "✓"; position: absolute; right: 10px; top: 50%; translate: 0 -50%; font-family: var(--marker); font-size: 1.6rem; color: var(--red);
}

/* rubber stamp Play button, docked under the thumb on phones */
.stamp-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(251, 248, 239, 0.94) 32%);
}
.stamp {
  position: relative; width: min(100%, 420px); min-height: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 6px 18px 8px; color: var(--red); background: rgba(255, 253, 246, 0.96);
  border: 4px solid var(--red); border-radius: 14px; box-shadow: inset 0 0 0 3px var(--paper-2), inset 0 0 0 5px var(--red), 2px 5px 10px rgba(60, 20, 0, 0.25);
  rotate: -1.5deg; transition: rotate 0.12s ease, scale 0.12s ease;
}
.stamp::after {
  content: ""; position: absolute; inset: 0; border-radius: 10px; pointer-events: none;
  background: radial-gradient(circle at 18% 30%, var(--paper-2) 0 1.5px, transparent 2px) 0 0 / 23px 17px,
    radial-gradient(circle at 70% 60%, var(--paper-2) 0 1px, transparent 1.6px) 0 0 / 31px 13px;
  opacity: 0.8;
}
.stamp:hover:not(:disabled) { background: #fff; rotate: 0deg; scale: 1.02; }
.stamp:active:not(:disabled) { scale: 0.96; }
.stamp-main { font-family: var(--marker); font-size: 2.3rem; line-height: 1; letter-spacing: 0.1em; text-transform: uppercase; }
.stamp-sub { font-size: 1rem; color: var(--ink); }

.menu-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%;
  padding: 50px 18px 18px; text-align: left; border: none; border-radius: 2px;
  box-shadow: 2px 6px 12px rgba(60, 40, 0, 0.25); transition: transform 0.12s ease;
}
.menu-tile strong { font-family: var(--marker); font-weight: 400; font-size: 1.4rem; }
.menu-tile small { color: #4a5276; font-size: 0.95rem; }
.menu-tile:hover:not(:disabled) { transform: rotate(0deg) translateY(-2px); background-color: #fff; }
.menu-panel .index-card { padding-top: 46px; }
.scrap-tile { background: var(--sticky); transform: rotate(-1.4deg); padding-top: 18px; }
.scrap-tile:hover:not(:disabled) { background: var(--sticky); }

.menu-code { display: flex; align-items: flex-end; gap: 10px; padding-top: 6px; }
.menu-code label { flex: 1; min-width: 0; font-size: 1.05rem; color: var(--ink); }
.menu-code input { font-size: 1.3rem; letter-spacing: 0.08em; }
.menu-code button { flex: none; min-height: 44px; padding: 0 18px; font-size: 1.15rem; }

/* leaderboard: polaroids of the podium, then the table */
.podium { list-style: none; margin: 4px 0 6px; padding: 0; display: flex; justify-content: center; align-items: flex-end; gap: 6px; }
.podium:empty { display: none; }
.polaroid {
  position: relative; flex: 0 1 112px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 6px 8px; background: #fff; box-shadow: 1px 5px 12px rgba(60, 40, 0, 0.3); rotate: -3deg;
}
.polaroid::before {
  content: ""; position: absolute; top: -7px; left: calc(50% - 7px); width: 14px; height: 14px; border-radius: 50%;
  background: var(--pin, #b8b8b8); box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.2), 1px 2px 2px rgba(0, 0, 0, 0.3);
}
.polaroid .photo {
  width: 100%; aspect-ratio: 1; display: block; background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 10px 10px; border: 1px solid rgba(0, 0, 0, 0.08);
}
.polaroid svg { width: 100%; height: 100%; display: block; }
.polaroid svg circle:first-child { stroke: var(--ink); stroke-width: 1.6; }
.polaroid .smile { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.polaroid text { font-family: var(--marker); font-size: 12px; fill: var(--ink); }
.polaroid .caption { max-width: 100%; font-family: var(--script); font-size: clamp(1.05rem, 4.4vw, 1.3rem); line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.polaroid small b { font-family: var(--marker); font-weight: 400; color: var(--red); }
.polaroid small { font-size: 0.8rem; white-space: nowrap; }
.polaroid.place-1 { order: 2; flex-basis: 128px; rotate: 1.5deg; translate: 0 -10px; --pin: #e9b10c; }
.polaroid.place-2 { order: 1; --pin: #a7b0be; }
.polaroid.place-3 { order: 3; rotate: 3deg; --pin: #c07a43; }

@media (min-width: 560px) {
  .mode-notes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mode-notes .mode-chip { grid-template-columns: minmax(0, 1fr); align-content: start; min-height: 150px; padding: 12px; }
  .mode-notes .mode-glyph { grid-row: auto; margin-bottom: 4px; }
  .mode-notes .mode-chip:not(.active) small { display: block; }
  .mode-notes .mode-chip.active::after { top: 10px; translate: none; }
}

/* desktop: hero and notebook side by side, stamp back on the page */
@media (min-width: 900px) {
  .doodle-bg { inset: 14px; box-shadow: 0 10px 30px rgba(40, 20, 0, 0.45); border-radius: 3px; }
  #menu {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px); align-items: start; align-content: center; gap: 24px 48px;
    width: min(1180px, 100%); margin: 0 auto; padding: 44px 48px;
  }
  .menu-hero { gap: 10px; padding-top: 24px; }
  .menu-logo { width: clamp(300px, 34vw, 440px); }
  .menu-subtitle { font-size: 1.7rem; max-width: 26ch; }
  .hero-doodle { display: block; margin-top: 8px; }
  .menu-corner { position: fixed; top: 30px; right: 34px; }
  .notebook-page { min-height: 470px; padding: 22px 26px 26px 52px; }
  .notebook-page::before { left: 10px; }
  .stamp-dock { position: static; padding: 6px 0 2px; background: none; }
  .stamp { width: auto; min-width: 260px; min-height: 96px; padding: 8px 36px 10px; rotate: -4deg; }
  .stamp-main { font-size: 2.9rem; }
  .menu-panel .index-card { flex-direction: row; align-items: baseline; justify-content: space-between; flex-wrap: wrap; padding: 44px 18px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .doodle-bg .creeps-live { display: none; }
  .doodle-bg .creeps-still { display: inline; }
  .menu-screen *, .menu-screen *::before, .menu-screen *::after, .doodle-bg * {
    animation: none !important; transition: none !important;
  }
  .doodle-bg .shots { opacity: 0.5; }
}

.paper-sheet {
  position: relative; padding: 22px 24px; display: flex; flex-direction: column; gap: 14px;
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px; box-shadow: 3px 8px 16px rgba(60, 40, 0, 0.3);
}
.paper-sheet::before {
  content: ""; position: absolute; left: calc(50% - 50px); top: -12px; width: 100px; height: 24px;
  background: rgba(255, 255, 255, 0.55); transform: rotate(-2deg);
}
/* leaderboard table */
.ranks-table { width: 100%; border-collapse: collapse; font-size: 1.15rem; }
.ranks-table th { font-family: var(--script); font-size: 1.4rem; text-align: left; border-bottom: 2px solid var(--ink); }
.ranks-table td { padding: 5px 4px; border-bottom: 1px solid var(--ink-soft); }
.ranks-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ranks-table .place { width: 2.2em; font-family: var(--marker); color: var(--muted); }
.ranks-table tr:nth-child(2) .place { color: var(--red); }
.ranks-table .who { overflow-wrap: anywhere; }
.ranks-table tr.me td { background: var(--highlight); }
.ranks-table .empty { border: none; color: var(--muted); padding: 12px 0; }

/* waiting room */
.room-sheet { width: min(760px, 100%); }
.room-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
.room-code {
  font-family: var(--marker); font-size: 1.8rem; letter-spacing: 0.12em; color: var(--ink);
  background: linear-gradient(transparent 55%, var(--highlight) 55%);
}
.room-badge { padding: 4px 12px; background: var(--sticky); box-shadow: 1px 2px 0 var(--ink-soft); transform: rotate(1.5deg); }
.room-share { display: flex; gap: 10px; align-items: flex-end; }
.room-share input { flex: 1; min-width: 0; font-size: 0.95rem; color: var(--muted); }
.room-share button { flex: none; }

.room-seats { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.room-seats:has(.team) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.team-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.team-head h3 { margin: 0; font-family: var(--script); font-size: 1.7rem; }
.team-0 .team-head h3 { color: var(--red); }
.team-1 .team-head h3 { color: #2b6cb0; }
.seat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.seat { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 6px 4px; border-bottom: 1.5px dashed var(--ink-soft); font-size: 1.2rem; }
.seat .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.seat .tag { font-size: 0.9rem; }
.seat .check { width: 1.2em; font-family: var(--marker); color: var(--green); }
.seat .remove { padding: 0 8px; }
.seat .level { min-width: 5.5em; font-size: 0.9rem; text-align: center; white-space: nowrap; }
.seat button.level { padding: 0 8px; }
.seat.me .name { text-decoration: underline wavy var(--red); text-underline-offset: 4px; }
.seat.open { color: var(--muted); }
.seat.open .dot { border-style: dashed; background: transparent; }
.seat.open .name { font-style: italic; }
.seat.open button { font-size: 0.95rem; }

.room-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.room-actions button { height: 48px; padding: 0 18px; font-size: 1.15rem; }
.room-actions [data-action="leave-room"] { margin-right: auto; }

/* game-over ranking and team tags in the in-game table */
#overlay ol.ranking { list-style: none; padding: 0; }
#overlay .row { gap: 12px; }
.team-tag {
  display: inline-block; min-width: 1.4em; padding: 0 4px; border-radius: 4px; text-align: center;
  font-family: var(--marker); font-size: 0.8rem; color: #fff;
}
.team-tag.team-0 { background: var(--red); }
.team-tag.team-1 { background: #2b6cb0; }

/* phones */
@media (max-width: 800px) {
  .paper-sheet { padding: 18px 16px; }
  .mode-chips.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .room-seats:has(.team) { grid-template-columns: minmax(0, 1fr); }
  .room-actions button { flex: 1; }
  .room-actions [data-action="leave-room"] { margin-right: 0; }
}
