/* ==========================================================================
   BUZZIES — "The Memo" design system
   Manila-folder office satire: torn index cards, typewriter jargon,
   rubber-stamp bonuses. See design tokens below.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Archivo+Black&family=Courier+Prime:wght@400;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root{
  /* ---- color tokens (light) ---- */
  --bg: #E8DCC4;
  --paper: #FFFFFF;
  --paper-shade: #F3ECDC;
  --ink: #1A1A1A;
  --ink-soft: #5b5648;
  --stamp-red: #C1392D;
  --corp-blue: #2C5F8A;
  --highlight-yellow: #F4D35E;
  --sticky-green: #6f8f63;
  --line: rgba(26,26,26,0.15);

  /* category base hues (tint scales by point value 2-5) */
  --cat-a-h: 355; /* Catalyst / Action -> rose */
  --cat-b-h: 205; /* Technology -> blue */
  --cat-c-h: 46;  /* Noun -> gold */
  --cat-d-h: 265; /* Impact -> purple */

  --radius: 8px;
  --font-display: 'Archivo Black', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-card: 'Courier Prime', monospace;
  --font-data: 'IBM Plex Mono', monospace;
}

body.dark{
  --bg: #121212;
  --paper: #1e1e1e;
  --paper-shade: #262626;
  --ink: #e5e5e5;
  --ink-soft: #a8a297;
  --line: rgba(229,229,229,0.15);
}

*{ box-sizing: border-box; }

html, body{
  margin:0; padding:0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
  transition: background .25s ease, color .25s ease;
}

button{ font-family: inherit; cursor: pointer; }
img{ max-width: 100%; display:block; }

/* ---- dim overlay for brightness slider ---- */
#dim-overlay{
  position: fixed; inset: 0;
  background: #000;
  opacity: 0; /* set via JS: 0 value => 0.8, 100 value => 0 */
  pointer-events: none;
  z-index: 500;
  transition: opacity .15s linear;
}

/* ---- theme toggle ---- */
.icon-btn{
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 50%;
  width: 40px; height: 40px;
  display: flex; align-items:center; justify-content:center;
  font-size: 1.1rem;
  box-shadow: 2px 2px 0 var(--ink);
}
#theme-toggle{
  position: fixed; top: 14px; right: 14px; z-index: 400;
}

/* ==========================================================================
   SCREENS
   ========================================================================== */
.screen{ display:none; min-height:100vh; }
.screen.active{ display:flex; flex-direction:column; }

/* ---- SPLASH ---- */
#splash-screen{
  align-items:center; justify-content:center;
  text-align:center; padding: 32px 20px;
  gap: 18px;
}
.splash-stamp{
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 10vw, 3.6rem);
  letter-spacing: 2px;
  color: var(--stamp-red);
  border: 6px double var(--stamp-red);
  padding: 10px 24px;
  transform: rotate(-3deg);
  display:inline-block;
}
.splash-sub{
  max-width: 420px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height:1.5;
}
.mode-select{
  display:flex; gap: 16px; flex-wrap: wrap; justify-content:center;
  margin-top: 12px;
}
.mode-btn{
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: 3px 3px 0 var(--ink);
  min-width: 160px;
  transition: transform .12s ease;
}
.mode-btn:hover{ transform: translate(-2px,-2px); box-shadow: 5px 5px 0 var(--ink); }
.mode-btn:active{ transform: translate(1px,1px); box-shadow: 2px 2px 0 var(--ink); }
.mode-fallback{
  flex-direction: column; gap: 4px; color: var(--ink); font-family: var(--font-body);
}
.mode-fallback strong{ font-family: var(--font-display); font-size: 1rem; }
.mode-fallback small{ color: var(--ink-soft); }
.loading-note{ font-family: var(--font-data); color: var(--ink-soft); font-size: 0.85rem; }

/* ==========================================================================
   GAME SCREEN — BoardGameArena-style: both boards stacked, wider desktop
   layout. (Dedicated mobile layout is a follow-up pass.)
   ========================================================================== */
#game-screen{
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px 24px;
  gap: 14px;
}

.game-header{
  display:flex; align-items:center; justify-content:space-between; gap:8px;
}
.score-block{
  display:flex; flex-direction:column; align-items:center;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 6px 12px;
  min-width: 74px;
  box-shadow: 2px 2px 0 var(--ink);
}
.score-label{ font-size: 0.65rem; text-transform:uppercase; letter-spacing:.5px; color: var(--ink-soft); }
.score-value{ font-family: var(--font-data); font-weight:600; font-size: 1.3rem; }
.pill-btn{
  background: var(--highlight-yellow);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 2px 2px 0 var(--ink);
}
#settings-btn img{ width: 20px; }

/* ---- board sections (opponent + player, BGA-style stacked layout) ---- */
.board-section{
  background: var(--paper-shade);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.opponent-section{ opacity: 0.96; }
.board-title-row{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom: 8px; position: relative;
}
.board-title{
  font-family: var(--font-data);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ink-soft);
}

.speech-bubble{
  position: absolute; top: -8px; right: 0;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.78rem;
  max-width: 220px;
  box-shadow: 2px 2px 0 var(--ink);
  z-index: 50;
  animation: pop-in .18s ease;
}
.speech-bubble::after{
  content:"";
  position:absolute; bottom:-8px; right: 24px;
  border-width: 8px 8px 0 0; border-style: solid;
  border-color: var(--ink) transparent transparent transparent;
}
.speech-label{ font-family: var(--font-data); font-size: 0.6rem; color: var(--corp-blue); margin-bottom:2px; }
.typing-dots span{
  display:inline-block; width:5px; height:5px; margin-right:3px;
  background: var(--ink-soft); border-radius:50%;
  animation: blink 1s infinite ease-in-out;
}
.typing-dots span:nth-child(2){ animation-delay: .15s; }
.typing-dots span:nth-child(3){ animation-delay: .3s; }
@keyframes blink{ 0%,80%,100%{ opacity:.2; } 40%{ opacity:1; } }
@keyframes pop-in{ from{ transform: scale(.8); opacity:0; } to{ transform: scale(1); opacity:1; } }

/* ---- target board: single row of 4 category columns (BGA/Lost Cities style) ---- */
.board-wrap{ position: relative; }
.target-board{
  display:grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.opponent-board .slot{ min-height: 56px; font-size: 0.75rem; }
.slot{
  min-height: 84px;
  border-radius: var(--radius);
  border: 2px dashed var(--line);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  text-align:center;
  padding: 8px 6px;
  font-family: var(--font-card);
  font-size: 0.85rem;
  font-weight: 700;
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
  position: relative;
}
.slot-cat-label{
  font-family: var(--font-data);
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.slot.filled .slot-cat-label{ color: inherit; opacity: 0.75; }
.slot.empty{ color: var(--ink-soft); font-family: var(--font-body); font-weight:500; font-size:0.68rem; }
.slot.staged{ border-style: solid; outline: 3px solid var(--highlight-yellow); }
.slot.drop-target{ background: var(--highlight-yellow); border-style: solid; transform: scale(1.03); }
.slot.drop-invalid{ background: transparent; opacity: 0.5; }
.slot.clickable{ cursor: pointer; }
.slot[data-cat="A"]{ --h: var(--cat-a-h); }
.slot[data-cat="B"]{ --h: var(--cat-b-h); }
.slot[data-cat="C"]{ --h: var(--cat-c-h); }
.slot[data-cat="D"]{ --h: var(--cat-d-h); }
/* shading scales with point value 2(light) -> 5(dark); light-on-dark handled via data-points */
.slot.filled[data-points="2"]{ background: hsl(var(--h) 55% 88%); color:#1a1a1a; border-color: hsl(var(--h) 45% 55%); }
.slot.filled[data-points="3"]{ background: hsl(var(--h) 55% 76%); color:#1a1a1a; border-color: hsl(var(--h) 45% 45%); }
.slot.filled[data-points="4"]{ background: hsl(var(--h) 50% 58%); color:#fff; border-color: hsl(var(--h) 45% 35%); }
.slot.filled[data-points="5"]{ background: hsl(var(--h) 55% 38%); color:#fff; border-color: hsl(var(--h) 45% 20%); }
body.dark .slot.filled[data-points="2"]{ background: hsl(var(--h) 35% 30%); color:#f0f0f0; }
body.dark .slot.filled[data-points="3"]{ background: hsl(var(--h) 40% 36%); color:#f5f5f5; }
body.dark .slot.filled[data-points="4"]{ background: hsl(var(--h) 45% 42%); color:#fff; }
body.dark .slot.filled[data-points="5"]{ background: hsl(var(--h) 55% 48%); color:#fff; }

#stamp-layer{
  position:absolute; inset:0; pointer-events:none;
  display:flex; align-items:center; justify-content:center;
  z-index: 60;
}
.stamp{
  font-family: var(--font-display);
  color: var(--stamp-red);
  border: 5px double var(--stamp-red);
  padding: 6px 16px;
  font-size: 1.1rem;
  transform: rotate(-8deg) scale(2.2);
  opacity: 0;
  background: rgba(255,255,255,0.85);
}
body.dark .stamp{ background: rgba(30,30,30,0.85); }
.stamp.stamp-play{ animation: stamp-down .55s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes stamp-down{
  0%{ opacity:0; transform: rotate(-8deg) scale(2.6); }
  55%{ opacity:1; transform: rotate(-8deg) scale(0.92); }
  70%{ transform: rotate(-8deg) scale(1.05); }
  100%{ opacity:1; transform: rotate(-8deg) scale(1); }
}

.turn-banner{
  text-align:center; font-family: var(--font-data);
  font-size: 0.8rem; color: var(--ink-soft);
}

/* ---- staging controls ---- */
.staging-controls{ display:flex; gap: 10px; }
.ghost-btn{
  flex:1;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 10px;
  font-weight: 600;
  font-size: 0.82rem;
  box-shadow: 2px 2px 0 var(--ink);
}
.ghost-btn.active-toggle{ background: var(--sticky-green); color:#fff; }
.ghost-btn:disabled{ opacity:.45; cursor:not-allowed; box-shadow:none; }
.ghost-btn.full-width{ width:100%; }
.primary-btn{
  flex:1;
  background: var(--stamp-red);
  color:#fff;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 10px;
  font-weight: 700;
  box-shadow: 2px 2px 0 var(--ink);
}
.primary-btn img{ height: 18px; margin: 0 auto; filter: brightness(0) invert(1); }
.primary-btn:disabled{ opacity:.4; cursor:not-allowed; box-shadow:none; }
.primary-btn.full-width{ width:100%; margin-top: 10px; }

/* ---- hand: grouped into 4 category lanes, sorted low->high like Lost Cities ---- */
.hand-wrap{ overflow-x: auto; padding-bottom: 4px; }
.hand{
  display:flex; gap: 4px; padding: 6px 2px 10px;
  min-height: 108px;
  align-items: flex-start;
}
.hand-group{
  display:flex; flex-direction:column; gap: 4px;
  padding: 4px 6px;
  border-right: 1.5px dashed var(--line);
}
.hand-group:last-child{ border-right: none; }
.hand-group-label{
  font-family: var(--font-data);
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 2px;
}
.hand-group-cards{ display:flex; gap: 8px; }
.card{
  flex: 0 0 auto;
  width: 92px;
  min-height: 88px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 8px 6px 10px;
  font-family: var(--font-card);
  font-size: 0.72rem;
  font-weight: 700;
  display:flex; flex-direction:column; justify-content:space-between;
  word-wrap: break-word;
  box-shadow: 2px 2px 0 var(--ink);
  position: relative;
  cursor: grab;
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:nth-child(odd){ transform: rotate(-1.5deg); }
.card:nth-child(even){ transform: rotate(1.5deg); }
.card:hover{ transform: translateY(-4px) rotate(0deg); }
/* "pulling to the front": a single click lifts the card up and above its
   neighbors without staging it yet — dblclick or drag actually plays it. */
.card.lifted{
  transform: translateY(-16px) rotate(0deg) scale(1.06);
  z-index: 30;
  box-shadow: 4px 6px 0 var(--ink);
  outline: 3px solid var(--corp-blue);
}
.card.selected{ outline: 3px solid var(--highlight-yellow); transform: translateY(-6px) rotate(0deg); }
.card.dragging{ opacity: 0.4; }
.card::after{
  content:"";
  position:absolute; left:8px; right:8px; bottom:6px;
  border-bottom: 1.5px dashed var(--line);
}
.card .card-cat{
  font-family: var(--font-data); font-size:0.55rem; text-transform:uppercase;
  color: var(--ink-soft); font-weight:600;
}
.card .card-pts{
  align-self:flex-end; font-family: var(--font-data); font-size:0.7rem;
  color: var(--stamp-red);
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-overlay{
  position: fixed; inset:0; background: rgba(0,0,0,0.5);
  display:flex; align-items:center; justify-content:center;
  z-index: 800; padding: 20px;
}
/* The [hidden] attribute and .modal-overlay have equal CSS specificity, and
   author styles beat the browser's built-in [hidden]{display:none} rule —
   so without this override every modal (including Round Over) renders on
   top of the page immediately, even before any game action happens. */
.modal-overlay[hidden]{
  display: none;
}
.modal-card{
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  width: 100%; max-width: 380px;
  box-shadow: 4px 4px 0 var(--ink);
  max-height: 84vh;
  display:flex; flex-direction:column;
}
.modal-tall{ max-height: 80vh; }
.modal-header{
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 16px; border-bottom: 2px solid var(--line);
}
.modal-header h2{ font-family: var(--font-display); font-size: 1.05rem; margin:0; }
.close-btn{
  background:none; border:none; font-size: 1.1rem; color: var(--ink);
}
.modal-body{ padding: 16px; display:flex; flex-direction:column; gap: 14px; }
.modal-body.scrollable{ overflow-y:auto; }
.slider-row{ display:flex; flex-direction:column; gap:6px; font-size:0.85rem; font-weight:600; }
.slider-row input[type="range"]{ width: 100%; accent-color: var(--stamp-red); }
.playbook-entry{
  border-left: 4px solid var(--corp-blue);
  padding-left: 10px; font-size: 0.85rem;
}
.playbook-entry small{ color: var(--ink-soft); }

/* ---- history entries ---- */
.history-entry{
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  border: 2px solid var(--line);
}
.history-entry.player{ background: hsl(var(--cat-b-h) 55% 92%); }
.history-entry.bot{ background: hsl(var(--cat-a-h) 55% 92%); }
body.dark .history-entry.player{ background: hsl(var(--cat-b-h) 35% 22%); }
body.dark .history-entry.bot{ background: hsl(var(--cat-a-h) 35% 22%); }
.history-author{ font-family: var(--font-data); font-size: 0.7rem; text-transform:uppercase; margin-bottom:4px; }
.history-bonus{ color: var(--stamp-red); font-weight:700; margin-top:4px; }
.empty-note{ color: var(--ink-soft); text-align:center; font-size:0.85rem; }

/* ---- responsive: desktop centers, capped 450px already handled by #game-screen ---- */
@media (min-width: 600px){
  body{ display:flex; justify-content:center; }
  #splash-screen{ width:100%; }
}
