:root {
  --cream: #f8f4e3;
  --cream2: #efe8cc;
  --ink: #5a4a32;
  --ink2: #8a7a5e;
  --green: #3f8f4a;
  --green2: #5fb05f;
  --sel: #f5b700;
  --bad: #e0453a;
  --sea: #7dd3c0;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;   /* one deliberate look, like the game's own menus */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink); }
body { display: flex; flex-direction: column; height: 100%; overscroll-behavior: none; font-family: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid var(--sel); outline-offset: 2px; }

.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: var(--cream); box-shadow: 0 2px 6px #0002; z-index: 2;
}
.topbar .title { flex: 1; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }
.iconbtn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--cream2); font-size: 22px; line-height: 1; }
.iconbtn:disabled { opacity: .35; }
.iconbtn.on { background: var(--sel); }
.pill { border: 0; border-radius: 22px; padding: 10px 18px; background: var(--green); color: white; font-weight: 700; font-size: 16px; }

#stage { flex: 1; position: relative; min-height: 0; touch-action: none; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  max-width: 92%; background: #000c; color: white; padding: 8px 14px; border-radius: 14px; font-size: 14px; text-align: center;
  pointer-events: none;
}
.comparebadge {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  background: var(--sel); color: var(--ink); padding: 6px 12px; border-radius: 12px; font-weight: 700; font-size: 14px;
}

.panel {
  background: var(--cream); padding: 8px 8px 4px; border-top: 2px solid var(--cream2);
  display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; align-items: center; min-height: 64px;
  scrollbar-width: none;
}
.panel::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 52px; height: 52px; padding: 2px 8px; border: 2px solid transparent; border-radius: 12px;
  background: var(--cream2); font-size: 11px; font-weight: 600; line-height: 1.1; text-align: center;
}
.chip .sw { width: 22px; height: 22px; border-radius: 6px; border: 1px solid #0003; font-size: 16px; display: flex; align-items: center; justify-content: center; }
.chip.on { border-color: var(--sel); background: #fff3c4; }
.chip.wide { min-width: 70px; }
.sep { flex: 0 0 2px; align-self: stretch; background: var(--cream2); margin: 4px 2px; }
.panel .note { flex: 0 0 auto; font-size: 13px; color: var(--ink2); padding: 0 6px; max-width: 260px; }

.tabs {
  display: flex; background: var(--cream); padding: 2px 4px calc(env(safe-area-inset-bottom) + 4px);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 4px 0; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; font-size: 11px; font-weight: 600; color: var(--ink2);
}
.tabs button span { font-size: 22px; line-height: 1.2; }
.tabs button.on { background: var(--cream2); color: var(--ink); }

.sheet { position: fixed; inset: 0; background: #0006; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheetbody {
  background: var(--cream); width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheetbody h2 { margin: 0 0 10px; }
.sheetbody hr { border: 0; border-top: 2px solid var(--cream2); margin: 10px 0; }
.big {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 14px; background: var(--cream2);
  padding: 13px 14px; margin: 6px 0; font-size: 16px; font-weight: 600;
}
.big.ghost { background: none; text-align: center; color: var(--ink2); }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; font-size: 16px; }
.row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--green); }
.row.slider { justify-content: space-between; }
.row.slider input { flex: 1; max-width: 50%; accent-color: var(--green); }
.help p { line-height: 1.45; margin: 6px 0; }
.help h3 { margin: 14px 0 4px; }

.dcard { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 14px; background: var(--cream2); margin: 6px 0; }
.dcard.cur { outline: 3px solid var(--sel); }
.dcard img { width: 70px; height: 60px; border-radius: 8px; background: var(--sea); object-fit: cover; image-rendering: pixelated; }
.dcard .dinfo { flex: 1; min-width: 0; }
.dcard .dname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dcard .ddate { font-size: 12px; color: var(--ink2); }
.dcard button { border: 0; background: var(--cream); border-radius: 10px; width: 40px; height: 40px; font-size: 18px; }

/* importer */
.importer { position: fixed; inset: 0; z-index: 20; background: #222; display: flex; flex-direction: column; }
.importer[hidden] { display: none; }
.impstage { flex: 1; position: relative; min-height: 0; touch-action: none; }
#impCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#impLoupe { position: absolute; top: 8px; left: 8px; width: 140px; height: 140px; border-radius: 50%; border: 3px solid white; box-shadow: 0 2px 8px #0008; pointer-events: none; }
#impLoupe.right { left: auto; right: 8px; }
.imphelp { background: var(--cream); padding: 8px 12px; font-size: 14px; }
.impbottom { background: var(--cream); display: flex; gap: 10px; padding: 6px 10px calc(env(safe-area-inset-bottom) + 10px); align-items: flex-start; }
#impPreview { width: 128px; height: 110px; image-rendering: pixelated; border-radius: 8px; flex: 0 0 auto; background: var(--sea); }
.impcolors { flex: 1; min-width: 0; }
.small { font-size: 12px; color: var(--ink2); margin-bottom: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatches button { border: 2px solid transparent; border-radius: 10px; padding: 3px 6px; background: var(--cream2); font-size: 11px; display: flex; align-items: center; gap: 4px; }
.swatches button i { width: 16px; height: 16px; border-radius: 4px; border: 1px solid #0004; display: inline-block; }
.swatches button.on { border-color: var(--sel); background: #fff3c4; }

/* ask Claude */
.panel.ask { flex-direction: column; align-items: stretch; gap: 6px; overflow: visible; }
.askrow { display: flex; gap: 6px; align-items: stretch; }
.askrow textarea {
  flex: 1; resize: none; border: 2px solid var(--cream2); border-radius: 12px; padding: 8px 10px;
  font: inherit; font-size: 16px; background: white; color: var(--ink);
}
.askrow .pill { min-width: 64px; }
.askreply { font-size: 14px; color: var(--ink2); min-height: 1.4em; max-height: 6.5em; overflow-y: auto; padding: 0 2px 4px; }
.textin { width: 100%; font: inherit; font-size: 18px; padding: 12px; border-radius: 12px; border: 2px solid var(--cream2); margin: 4px 0 8px; }

/* first-run card over a blank island */
.startcard {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 32px)); background: var(--cream); border-radius: 20px;
  box-shadow: 0 8px 30px #0004; padding: 18px; display: flex; flex-direction: column; gap: 10px;
}
.startcard h2 { margin: 0; font-size: 22px; }
.startcard p { margin: 0; line-height: 1.45; }
.startcard .pill { padding: 14px; font-size: 17px; }
.startcard details { font-size: 14px; color: var(--ink2); }
.startcard summary { cursor: pointer; font-weight: 700; color: var(--ink); padding: 4px 0; }
.linkbtn { border: 0; background: none; color: var(--ink2); font-weight: 700; text-decoration: underline; padding: 6px; }

/* shared designs */
.livebadge { flex: 0 0 auto; background: var(--green); color: white; font-weight: 800; font-size: 13px; border-radius: 12px; padding: 4px 9px; }
.dhead { margin: 14px 0 4px; font-size: 15px; }
.dnote { margin: 4px 0 8px; color: var(--ink2); font-size: 14px; }

/* mouse readout */
.status {
  position: absolute; left: 10px; bottom: 10px; background: #000a; color: white; font-weight: 700;
  padding: 4px 10px; border-radius: 10px; font-size: 13px; pointer-events: none; font-variant-numeric: tabular-nums;
}

/* computer: tools in a side column next to a big map */
@media (min-width: 900px) and (min-height: 500px) {
  body {
    display: grid; grid-template-columns: 330px 1fr; grid-template-rows: auto auto 1fr;
    grid-template-areas: "top top" "tabs stage" "panel stage";
  }
  .topbar { grid-area: top; }
  #stage { grid-area: stage; }
  .tabs { grid-area: tabs; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 10px; border-bottom: 2px solid var(--cream2); }
  .tabs button { padding: 6px 0; }
  .panel { grid-area: panel; flex-wrap: wrap; align-content: flex-start; overflow-y: auto; border-top: 0; padding: 12px 10px; gap: 8px; }
  .panel .note { flex-basis: 100%; max-width: none; padding: 0 2px; }
  .sep { flex: 0 0 100%; height: 2px; margin: 2px 0; }
  .chip { min-width: 66px; }
  .panel.ask .askrow { flex-direction: column; }
  .panel.ask textarea { min-height: 120px; }
  .panel.ask .pill { padding: 12px; }
  .askreply { max-height: none; font-size: 15px; }
  .sheet { align-items: center; }
  .sheetbody { border-radius: 20px; padding-bottom: 16px; }
}

/* build guide */
.panel.guide { flex-direction: column; align-items: stretch; gap: 6px; overflow-y: auto; max-height: 42vh; }
.ghead { display: flex; align-items: center; gap: 10px; }
.gbar { flex: 1; height: 10px; border-radius: 6px; background: var(--cream2); overflow: hidden; }
.gbar span { display: block; height: 100%; background: var(--green2); }
.gcount { font-size: 13px; font-weight: 800; color: var(--ink2); white-space: nowrap; }
.gupd { font-size: 14px; }
.gphase { border-radius: 12px; background: #fffaf0; }
.gph { width: 100%; display: flex; justify-content: space-between; gap: 8px; align-items: center; border: 0; background: none; padding: 10px 12px; text-align: left; font-size: 15px; }
.gph span { font-size: 13px; color: var(--ink2); font-weight: 700; white-space: nowrap; }
.gphase.open .gph { border-bottom: 2px solid var(--cream2); }
.gtip { margin: 8px 12px; font-size: 13px; color: var(--ink2); line-height: 1.4; }
.gjob { display: flex; align-items: flex-start; gap: 8px; padding: 4px 10px; }
.gjob input { width: 22px; height: 22px; margin-top: 8px; flex: 0 0 auto; accent-color: var(--green); }
.gtext { flex: 1; display: flex; gap: 8px; align-items: flex-start; border: 2px solid transparent; background: none; border-radius: 10px; padding: 6px 8px; text-align: left; }
.gjob.on .gtext { border-color: var(--sel); background: #fff3c4; }
.gtext b { display: block; font-size: 14px; }
.gtext em { font-style: normal; font-size: 12px; color: var(--ink2); margin-right: 6px; }
.gtext small { font-size: 12px; color: var(--ink2); }
.gdot { flex: 0 0 auto; width: 14px; height: 14px; border-radius: 4px; margin-top: 3px; border: 1px solid #0003; }
.gjob.done b { text-decoration: line-through; opacity: .55; }
@media (min-width: 900px) and (min-height: 500px) { .panel.guide { max-height: none; flex-wrap: nowrap; } }
