:root {
  --bg: #efebe4;
  --surface: #fbfaf7;
  --ink: #2a2622;
  --muted: #7b7268;
  --line: #e0d9ce;
  --accent: #3d6a58;
  --accent-soft: #dfe9e3;
  --good: #4a8a5a;
  --warn: #c58a2a;
  --bad: #b5523b;
  --sky-top: #e6e1d8;
  --sky-bottom: #f5f2ec;
  --ground: #d8ccb5;
  --ground-edge: #b5a589;
  --ground-speck: #8c7c62;
  --shadow: rgba(40, 30, 20, 0.32);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18;
    --surface: #252320;
    --ink: #ece6dc;
    --muted: #a0978b;
    --line: #37322c;
    --accent: #7db39b;
    --accent-soft: #2a3a33;
    --good: #6fb07f;
    --warn: #d9a44a;
    --bad: #d9745c;
    --sky-top: #17191a;
    --sky-bottom: #24272a;
    --ground: #3a342b;
    --ground-edge: #5a4f40;
    --ground-speck: #7a6c58;
    --shadow: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 var(--font);
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }

svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

kbd {
  font: 500 11px/1 var(--font);
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg);
}

.app {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100vh;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  overflow: hidden;
  min-width: 0;
}

#world {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.status {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}

.status:empty { display: none; }
.muted { color: var(--muted); }

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.pill-good { background: var(--good); border-color: var(--good); color: #fff; }
.pill-warn { color: var(--warn); border-color: currentColor; }

.toast {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
  opacity: 0;
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.help-toggle {
  position: absolute;
  left: 14px;
  top: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.help-toggle[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

.help {
  position: absolute;
  left: 14px;
  top: 54px;
  width: 360px;
  max-width: calc(100% - 28px);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px var(--shadow);
}

.help dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 13px;
}

.help dt { font-weight: 600; white-space: nowrap; }
.help dd { margin: 0; color: var(--muted); }
.help-foot { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }

.drop-hint {
  position: absolute;
  inset: 12px;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent-soft) 70%, transparent);
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}

.is-dropping .drop-hint { display: grid; }

/* ---------- panel ---------- */

.panel {
  border-left: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}

.panel-head { padding: 16px 18px 6px; }
.panel-head h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }

.panel-section { padding: 12px 18px 16px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }

.panel-section h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.thumb {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  min-width: 0;
}

.thumb { user-select: none; touch-action: none; }
.thumb img { width: 100%; height: 44px; object-fit: contain; pointer-events: none; }

.thumb-count {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--surface);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
}

.thumb:has(.thumb-count)::after { display: none; }

.drag-ghost {
  position: fixed;
  z-index: 10;
  transform: translate(-50%, -50%);
  opacity: 0.8;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px var(--shadow));
}

.is-tray-dragging, .is-tray-dragging * { cursor: grabbing !important; user-select: none; }
.thumb-name { font-size: 11.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.thumb:hover { border-color: var(--muted); }
.thumb.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb.is-selected .thumb-name { color: var(--ink); }

.thumb.is-placed::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.thumb:not(.is-placed):not(.thumb-add) img { opacity: 0.45; }

.thumb-add { justify-content: center; border-style: dashed; color: var(--muted); }
.thumb-add svg { width: 22px; height: 22px; margin: 11px 0; }

.detail-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.detail-head img { width: 56px; height: 44px; object-fit: contain; }
.detail-name { font-weight: 600; }
.detail-sub { font-size: 12px; color: var(--muted); }

.field {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.field > span:first-child { color: var(--muted); font-size: 13px; }
.field select { grid-column: 2 / 4; }
.field .num.wide { grid-column: 2 / 4; justify-self: start; }

.field input[type="range"] { width: 100%; accent-color: var(--accent); }

.num { display: inline-flex; align-items: center; gap: 4px; }
.num em { font-style: normal; color: var(--muted); font-size: 12.5px; }
.num input { width: 64px; }
.num.wide input { width: 96px; }

input[type="number"], select {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

input[type="number"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field-note { margin: -2px 0 12px 64px; font-size: 12px; color: var(--muted); }

.row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: var(--surface);
  font-weight: 500;
  cursor: pointer;
}

.btn kbd { border-color: transparent; background: rgba(255, 255, 255, 0.18); color: inherit; }
.btn:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--muted); filter: none; }
.btn-quiet.is-armed { border-color: var(--bad); color: var(--bad); }

.hands { display: grid; gap: 6px; }

.hand {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.hand-tag {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  font-size: 11px;
  font-weight: 600;
}

.hand.is-free { color: var(--muted); }
.hand.is-free .hand-tag { border-style: dashed; }
.hand-rock { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hand-state { font-size: 12px; color: var(--muted); }

.opt { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.opt > span { color: var(--muted); font-size: 13px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg-btn { padding: 4px 11px; border: 0; background: transparent; cursor: pointer; min-width: 34px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.is-on { background: var(--accent); color: var(--surface); }

.sound { display: flex; align-items: center; gap: 8px; }
.sound input[type="range"] { width: 110px; accent-color: var(--accent); }
.sound .toggle { min-width: 62px; justify-content: center; }

.toggles { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 14px; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
}

.toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: 42vh; }
  .tray { grid-template-columns: repeat(4, 1fr); }
}
