
:root{
  --bg:#e8e8e6;
  --paper:#efefec;
  --ink:#3a3127;
  --line:#7ec7f7;
  --line-soft:#c9e7fb;
  --pink:#f7d8e5;
  --blue:#d8eefc;
  --wood1:#d7b47d;
  --wood2:#c79a5d;
  --wood3:#b88547;
  --slot:#f8f4ee;
  --shadow:0 12px 32px rgba(46,46,46,.12);
  --radius:18px;
  --navbar-h:72px;
  --hud-h:180px;
}

*{box-sizing:border-box}
html,body{margin:0;height:100%;font-family:Inter,system-ui,sans-serif;background:var(--bg);color:var(--ink);overflow:hidden}
body{
  background:
    linear-gradient(transparent 0 0),
    radial-gradient(circle at 20% 18%, rgba(255,255,255,.58), transparent 28%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,.42), transparent 22%),
    linear-gradient(90deg, transparent 0 100%);
}
body::before{
  content:"";
  position:fixed; inset:0;
  background:
    linear-gradient(90deg, transparent 0 6%, rgba(216,238,252,.35) 6% 12%, transparent 12% 18%, rgba(247,216,229,.28) 18% 24%, transparent 24% 34%, rgba(216,238,252,.2) 34% 38%, transparent 38% 100%),
    linear-gradient(transparent 0 14%, rgba(247,216,229,.22) 14% 21%, transparent 21% 31%, rgba(216,238,252,.17) 31% 36%, transparent 36% 52%, rgba(247,216,229,.18) 52% 59%, transparent 59% 100%),
    radial-gradient(rgba(0,0,0,.03) .8px, transparent .8px);
  background-size: 240px 240px, 240px 240px, 6px 6px;
  opacity:.7; pointer-events:none;
}
.glass{
  background:rgba(255,255,255,.62);
  backdrop-filter: blur(8px);
  border:1px solid rgba(255,255,255,.65);
  box-shadow:var(--shadow);
}
#appShell{position:relative;height:100%}
#topbar{
  position:absolute; top:12px; left:12px; right:12px; z-index:50;
  height:var(--navbar-h); border-radius:10px; display:flex; align-items:center; justify-content:space-between;
  padding:0 16px 0 18px; transition:transform .35s ease, opacity .35s ease;
}
#topbar.hiddenBar{transform:translateY(-110%); opacity:0}
h1{
  margin:0; font-family:"Alfa Slab One", serif; font-size:clamp(1.3rem, 2vw, 2rem);
  letter-spacing:.02em; color:#8d2e2e; text-shadow:0 1px 0 #fff;
}
.topbarActions{display:flex; gap:10px}
.iconBtn,.actionBtn,.miniChip{
  border:none;
  border-radius:10px;
  cursor:pointer;
  font:600 14px/1 Inter,sans-serif;
}
.iconBtn{background:#fff; min-width:42px; height:42px; padding:0 14px; color:var(--ink)}
.infoOnly{font-size:22px; width:42px; padding:0}
#topbarToggle{
  position:absolute; left:12px; bottom:12px; z-index:51;
  border:none; border-radius:999px; width:44px; height:44px; box-shadow:var(--shadow);
  background:rgba(255,255,255,.88); display:none; cursor:pointer;
}
#layout{
  position:absolute; inset:0; display:grid;
  grid-template-rows: 1fr var(--hud-h);
}
#mapStage{
  position:relative;
  min-height:0;
  overflow:visible;
  padding-top:calc(var(--navbar-h) + 20px);
  z-index:10;
}
#mapBackdrop{position:absolute; inset:0; pointer-events:none}
#mapSvg,#tileLayer{position:absolute; left:0; right:0; top:0}
#mapSvg{
  bottom:0;
  width:100%;
  height:100%;
  z-index:5;
}
#tileLayer{
  bottom:calc(-1 * var(--hud-h));
  z-index:40;
  pointer-events:none;
}
.country{fill:rgba(192,192,192,.65); stroke:var(--line); stroke-width:.7px; vector-effect:non-scaling-stroke; cursor:default}
.country.solved{fill:url(#woodPattern); cursor:pointer}
.country.activeHint{filter:drop-shadow(0 0 3px rgba(126,199,247,.35))}
.country:hover.solved{stroke-width:1.2px}
#hud{
  position:relative;
  z-index:30;
  margin:0 12px 12px;
  border-radius:10px;
  display:grid;
  grid-template-columns:minmax(250px, 1fr) 2fr 250px;
  gap:16px;
  align-items:center;
  padding:14px 18px;
}
.scoreCluster{display:flex; gap:12px}
.scoreBox{
  background:rgba(255,255,255,.68); border-radius:10px; padding:12px 14px; min-width:92px;
  display:flex; flex-direction:column; justify-content:center;
}
.kicker{font-size:12px; text-transform:uppercase; letter-spacing:.12em; color:#6a6258}
.scoreBox strong{font-size:1.45rem}
#countryPrompt{display:grid; gap:10px; align-items:center}
.promptHeader{display:flex; justify-content:space-between; gap:12px; align-items:flex-end}
.promptHeader h2{margin:4px 0 0; font-size:clamp(1.1rem, 2vw, 1.6rem); letter-spacing:.18em}
#answerRow{display:flex; gap:8px; flex-wrap:wrap; align-items:center; min-height:56px}
.slot{
  width:48px; height:54px; border-radius0px; background:var(--slot);
  border:2px dashed rgba(58,49,39,.18); display:grid; place-items:center; position:relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.04);
}
.slot.filled{border-style:solid; border-color:rgba(126,199,247,.6)}
.hudActions{display:flex; gap:10px; align-items:center}
.actionBtn{height:44px; padding:0 16px; background:#8d2e2e; color:#fff}
.actionBtn.secondary{background:#2e647e}
.actionBtn.hidden{display:none}
.miniChip{height:34px; padding:0 12px; background:rgba(126,199,247,.18); color:#255069}
.miniChip:disabled{opacity:.5; cursor:not-allowed}
#recentBox{justify-self:end; text-align:right}
#recentSolved{font-weight:700; font-size:1rem; padding-top:8px}
.tile{
  position:absolute; width:58px; height:58px; border-radius:10px; pointer-events:auto;
  background:
    radial-gradient(circle at 28% 18%, rgba(255,255,255,.48), transparent 22%),
    repeating-linear-gradient(8deg, rgba(255,255,255,.08) 0 3px, rgba(103,65,31,.06) 3px 7px),
    linear-gradient(140deg, #efd3a3, #ddb474 55%, #c38f4d 100%);
  border:1px solid rgba(108,72,28,.28);
  box-shadow:0 10px 16px rgba(72,51,20,.2), inset 0 1px 0 rgba(255,255,255,.45);
  display:flex; align-items:center; justify-content:center; user-select:none;
  touch-action:none;
}
.tile span{
  font:700 28px/1 Georgia,serif; color:#412a16; text-shadow:0 1px 0 rgba(255,255,255,.35);
}
.tile small{
  position:absolute; right:8px; bottom:5px; font:700 12px/1 Inter,sans-serif; color:#5a3f22;
}
.tile.dragging{box-shadow:0 18px 24px rgba(72,51,20,.28); z-index:999}
#loadingShield{
  position:absolute; inset:0; z-index:60; display:grid; place-items:center;
  background:rgba(232,232,230,.55)
}
.loadingCard{padding:22px 26px; border-radius:10px; text-align:center}
.spinner{
  width:34px;height:34px;margin:0 auto 10px;border:3px solid rgba(58,49,39,.15);
  border-top-color:#8d2e2e;border-radius:50%; animation:spin 1s linear infinite
}
@keyframes spin{to{transform:rotate(360deg)}}
#toastLayer{
  position:absolute; inset:0; z-index:70; pointer-events:none; display:grid; place-items:center;
}
.toast{
  padding:14px 18px; border-radius:999px; background:rgba(255,255,255,.95); box-shadow:var(--shadow);
  font-weight:700; animation:toastUp 1.1s ease forwards;
}
@keyframes toastUp{
  0%{opacity:0; transform:translateY(18px) scale(.94)}
  15%{opacity:1; transform:translateY(0) scale(1)}
  75%{opacity:1}
  100%{opacity:0; transform:translateY(-16px) scale(1.02)}
}
.modal{
  position:fixed; inset:0; z-index:120; display:grid; place-items:center; padding:20px;
}
#modalBackdrop{
  position:fixed; inset:0; z-index:110; background:rgba(38,37,35,.28)
}
.hidden{display:none!important}
.modalCard{
  width:min(780px, 92vw);
  max-height:min(78vh, 760px);
  overflow:auto;
  position:relative;
  border-radius:10px;
  padding:22px 22px 18px;
}
.modalCard.compact{width:min(380px, 90vw)}
.modalClose{
  position:absolute; right:14px; top:12px; border:none; background:transparent; font-size:28px; cursor:pointer; color:#51473e;
}
.modalBody{display:grid; gap:12px}
.formBody label{display:grid; gap:6px}
input{
  width:100%; height:42px; border-radius:10px; border:1px solid rgba(58,49,39,.16); padding:0 12px; font:500 15px Inter,sans-serif
}
.statusLine{min-height:20px; margin:4px 0 0; color:#8d2e2e}
.tableWrap{margin-top:12px; max-height:48vh; overflow:auto}
.tableWrap.tall{max-height:58vh}
.scoreTable{width:100%; border-collapse:collapse}
.scoreTable th,.scoreTable td{padding:10px 6px; text-align:left}
.scoreTable thead th{position:sticky; top:0; background:rgba(255,255,255,.88)}
.scoreTable tbody tr:nth-child(odd){background:rgba(255,255,255,.25)}
.modalFooterLinks{display:flex; gap:10px; flex-wrap:wrap; margin-top:16px; font-size:14px}
.scoresHeader,.modalTopActions{display:flex; justify-content:space-between; align-items:center}
.sourceList{display:grid; gap:10px; padding-left:18px}
#orientationOverlay{
  position:fixed; inset:0; z-index:140; background:rgba(32,30,28,.62); display:grid; place-items:center; padding:16px
}
.orientationCard{padding:24px; text-align:center; border-radius:10px}
@media (max-width: 900px){
  :root{--hud-h:230px}
  #hud{grid-template-columns:1fr; align-items:start; gap:10px}
  #recentBox{justify-self:start; text-align:left}
}
@media (max-width: 700px){
  :root{--navbar-h:64px; --hud-h:250px}
  .scoreCluster{flex-wrap:wrap}
  .tile{width:64px; height:64px}
}

.country.solved{fill:url(#woodPattern); cursor:pointer}
.country.solved.passed{fill:url(#passWoodPattern)}

.answerActionRow{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:14px;
  flex-wrap:wrap;
}

#answerRow{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
  min-height:56px;
  justify-content:center;
}

.hudActions{
  display:flex;
  gap:10px;
  align-items:center;
}

@media (max-width: 900px) {
  :root {
    --hud-h: 210px;
  }

  #hud {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 14px 12px;
    align-items: start;
  }

  .scoreCluster {
    gap: 8px;
    flex-wrap: nowrap;
  }

  .scoreBox {
    min-width: 78px;
    padding: 10px 12px;
  }

  #countryPrompt {
    gap: 8px;
  }

  .promptHeader {
    align-items: start;
  }

  .promptHeader h2 {
    font-size: clamp(1rem, 3.8vw, 1.3rem);
    letter-spacing: 0.12em;
    line-height: 1.05;
    word-break: break-word;
  }

  .answerActionRow {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
  }

  #answerRow {
    min-height: 52px;
    gap: 6px;
  }

  .slot {
    width: 42px;
    height: 48px;
  }

  .hudActions {
    position: sticky;
    right: 0;
    bottom: 0;
    justify-self: end;
    align-self: center;
    background: rgba(239, 239, 236, 0.92);
    padding-left: 6px;
  }

  .actionBtn {
    height: 42px;
    padding: 0 14px;
    white-space: nowrap;
  }

  #recentBox {
    display: none;
  }
}

@media (max-width: 700px) {
  :root {
    --navbar-h: 64px;
    --hud-h: 190px;
  }

  .scoreBox strong {
    font-size: 1.2rem;
  }

  .kicker {
    font-size: 11px;
  }

  .slot {
    width: 38px;
    height: 44px;
  }

  .actionBtn {
    height: 40px;
    padding: 0 12px;
    font-size: 13px;
  }
}