:root {
  --bg: #0b0e13;
  --panel: #121720;
  --card: #18202b;
  --card-2: #1f2937;
  --line: #2f3b4d;
  --text: #eef2f7;
  --muted: #b6c2d1;
  --accent: #fcd34d;
  --good: #86efac;
  --bad: #fca5a5;
  --focus: #7dd3fc;
  --danger: #ef4444;
  --panel-width: 440px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4em 0.8em;
  cursor: pointer;
  min-height: 2.25rem;
}
button:hover:not(:disabled) { border-color: #5b6f89; background: #263243; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-width); height: 100%; overflow: hidden; }
.mine { position: relative; min-width: 0; min-height: 0; }
.mine-scroller { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; cursor: crosshair; }
.mine-scroller.panning { cursor: grabbing; }
.mine-scroller canvas { position: sticky; top: 0; left: 0; display: block; }
.mine-spacer { position: absolute; top: 0; left: 0; pointer-events: none; }
.mine-toolbar {
  position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; align-items: center;
  background: rgba(11, 14, 19, 0.85); border: 1px solid var(--line); border-radius: 10px; padding: 6px;
}
.mine-toolbar output { min-width: 3.5em; text-align: center; font-size: 14px; }
.mine-hint {
  max-width: 560px;
  background: rgba(11, 14, 19, 0.88); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 15px;
}
.mine-hint:empty { display: none; }
.range-legend {
  position: absolute; right: 12px; top: 12px; display: grid; gap: 4px; font-size: 14px;
  background: rgba(11, 14, 19, 0.88); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.range-legend[hidden] { display: none; }
.ring { display: inline-block; width: 26px; height: 0; border-top: 3px solid #7dd3fc; margin-right: 8px; vertical-align: middle; }
.ring.dashed { border-top: 3px dashed #fcd34d; }

.panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-head h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.panel-head h1 small { color: var(--muted); font-weight: 500; }
.head-buttons { display: flex; gap: 6px; align-items: center; }
.chip-button { font-size: 15px; }
.icon-button { font-size: 18px; width: 2.4rem; padding: 0; }
.stats { display: grid; grid-template-columns: 0.8fr 1fr 1.15fr 0.8fr 0.8fr; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; min-width: 0; }
.stat .label { display: block; font-size: 14px; color: var(--muted); }
.stat .value { white-space: nowrap; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat button { width: 100%; padding: 0.1em 0.3em; min-height: 0; font-weight: 700; }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px 24px; display: grid; gap: 10px; align-content: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-width: 0; }
.card h2 { font-size: 16px; margin: 0 0 8px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card h2 .sub { font-size: 14px; color: var(--muted); font-weight: 500; }
.card p { margin: 0.3em 0; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.primary { background: #2563eb; border-color: #3b82f6; font-weight: 700; }
.primary:hover:not(:disabled) { background: #1d4ed8; }
.danger { border-color: #7f1d1d; background: #3b1616; }
.danger:hover:not(:disabled) { background: #521c1c; }
.danger::before { content: '⚠ '; }
.big { width: 100%; padding: 0.6em; font-size: 17px; }
.slots { display: flex; gap: 6px; margin: 6px 0; }
.slot { width: 44px; height: 44px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; }
.slot.filled { border-style: solid; }
.timer { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: 15px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.unit-head { display: flex; gap: 10px; align-items: center; }
.unit-head .names { min-width: 0; }
.unit-head .name { font-size: 17px; font-weight: 700; }
.unit-head .orig { font-size: 14px; color: var(--muted); }
.tag { display: inline-block; font-size: 14px; border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; margin-right: 4px; }
.tag.fly { border-color: #a78bfa; color: #ddd6fe; }
.abilities { margin: 6px 0 0; padding-left: 1.2em; font-size: 15px; }
.abilities li { margin: 2px 0; }
.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin-top: 8px; }
.actions button { text-align: left; }
.actions .why { display: block; font-size: 14px; color: var(--muted); }
.log { list-style: none; padding: 0; margin: 6px 0 0; font-size: 14px; display: grid; gap: 2px; max-height: 12em; overflow-y: auto; }
.log li { color: var(--muted); }
.log li.important { color: var(--text); }
.progress { height: 6px; background: #0e1219; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress div { height: 100%; background: var(--accent); }
.shop { display: grid; gap: 8px; }
.shop-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.shop-item .desc { font-size: 14px; color: var(--muted); grid-column: 1 / -1; }
.diff-options { display: grid; gap: 6px; margin: 8px 0; }
.diff-options label { display: flex; gap: 8px; align-items: flex-start; background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.diff-options input { margin-top: 0.35em; }

.popover-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(92vw, 560px);
  max-height: min(75vh, 720px); overflow-y: auto; background: #151b25; border: 1px solid #3a4a60;
  border-radius: 12px; padding: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.recipe-group h3 { font-size: 15px; margin: 8px 0 4px; color: var(--accent); }
.recipe { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 4px 6px; border-radius: 8px; font-size: 14px; }
.recipe.available { background: rgba(134, 239, 172, 0.12); outline: 1px solid rgba(134, 239, 172, 0.5); }
.recipe .result { display: flex; align-items: center; gap: 4px; min-width: 9.5em; font-weight: 600; }
.recipe .op { color: var(--muted); font-weight: 700; padding: 0 2px; }
.recipe .alt { color: #fcd34d; font-weight: 700; padding: 0 2px; }
.recipe .ing { display: inline-flex; align-items: center; gap: 2px; }
.recipe .badge { font-size: 13px; color: #052e16; background: var(--good); border-radius: 999px; padding: 0 6px; }
.recipe .cost { color: var(--accent); }

dialog { background: #151b25; color: var(--text); border: 1px solid #3a4a60; border-radius: 14px; padding: 0; width: min(94vw, 520px); max-height: 88vh; }
dialog.wide { width: min(96vw, 1100px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #151b25; z-index: 1; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 14px 16px; overflow: auto; }
.setting { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
.setting input { margin-top: 0.35em; width: 1.1em; height: 1.1em; }
.audio-settings { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 6px 12px 10px; }
.audio-settings legend { color: var(--accent); font-weight: 700; padding: 0 5px; }
.audio-settings .muted { margin: 8px 0 0; }
.audio-setting { display: grid; grid-template-columns: 6em 1fr 3.5em; gap: 10px; align-items: center; margin: 8px 0; }
.audio-setting input { width: 100%; accent-color: #3b82f6; }
.audio-setting output { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.audio-test { border: 1px solid #2563eb; border-radius: 10px; margin: 0 0 14px; padding: 6px 12px 10px; }
.audio-test legend { color: var(--focus); font-weight: 700; padding: 0 5px; }
.audio-test-row { display: grid; grid-template-columns: 11em 1fr; gap: 10px; align-items: center; margin: 8px 0; }
.audio-test-row output { color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs [aria-selected="true"] { background: #2563eb; border-color: #3b82f6; }
.enc { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 12px; min-height: 0; }
.enc-list { display: grid; gap: 4px; max-height: 64vh; overflow-y: auto; align-content: start; }
.enc-list button { display: flex; align-items: center; gap: 8px; text-align: left; }
.enc-list button[aria-current="true"] { border-color: var(--accent); background: #2a2410; }
.enc-detail { min-width: 0; max-height: 64vh; overflow-y: auto; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.choices button { display: flex; align-items: center; gap: 8px; }
.original-text { font-size: 14px; color: var(--muted); white-space: pre-wrap; }
details summary { cursor: pointer; font-size: 14px; color: var(--muted); }

@media (max-width: 900px) {
  :root { --panel-width: 100%; }
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(260px, 52vh) minmax(0, 1fr); }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .enc { grid-template-columns: 1fr; }
  .enc-list { max-height: 30vh; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

.paused-banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(11, 14, 19, 0.9); border: 2px solid var(--accent); border-radius: 12px;
  padding: 10px 20px; font-size: 20px; font-weight: 700; pointer-events: none;
}
.paused-banner[hidden] { display: none; }

.cell-legend {
  position: absolute; right: 12px; bottom: 12px; display: grid; gap: 3px; font-size: 14px;
  background: rgba(11, 14, 19, 0.88); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.swatch { display: inline-block; width: 16px; height: 16px; margin-right: 8px; vertical-align: -3px; border: 2px solid; border-radius: 3px; }
.swatch.gem { background: rgba(96, 165, 250, 0.35); border-color: #60a5fa; }
.swatch.special { background: rgba(250, 204, 21, 0.35); border-color: #facc15; }
.swatch.stone { background: rgba(168, 162, 158, 0.45); border-color: #a8a29e; }
.swatch.slate { border-style: dashed; border-color: #34d399;
  background: repeating-linear-gradient(135deg, rgba(52, 211, 153, 0.5) 0 2px, transparent 2px 6px); }
@media (max-width: 900px) { .cell-legend { display: none; } }

.sandbox-bar {
  position: absolute; top: 64px; left: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; max-width: calc(100% - 24px);
  background: rgba(40, 20, 60, 0.92); border: 1px solid #c084fc; border-radius: 10px; padding: 6px 10px; font-size: 14px;
}
.sandbox-bar[hidden] { display: none; }
.sandbox-bar select { font: inherit; max-width: 16em; }
.sandbox-bar button[aria-pressed="true"] { outline: 2px solid #c084fc; }

/* bottom-left dock: field hints */
.mine-dock {
  position: absolute; left: 12px; bottom: 12px; z-index: 5; display: flex; flex-direction: column; align-items: flex-start;
  gap: 8px; width: min(400px, calc(100% - 24px)); pointer-events: none;
}
.mine-dock > * { pointer-events: auto; }
/* selected object's info: first card of the side panel, only while something is selected */
.unit-info { position: relative; border-color: #5b6f89; }
.unit-info[hidden] { display: none; }
.unit-info h2 { padding-right: 2.2rem; }
.card-close { position: absolute; top: 8px; right: 8px; width: 2rem; height: 2rem; padding: 0; font-size: 15px; }
/* action buttons floating next to the selected object */
.unit-actions {
  position: absolute; left: 0; top: 0; z-index: 6; display: flex; gap: 6px; width: max-content; will-change: transform;
}
.unit-actions[hidden] { display: none; }
/* compact round icon buttons; full label as tooltip */
.icon-action {
  position: relative; width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 50%;
  font-size: 18px; line-height: 1; display: grid; place-items: center; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
}
.icon-action:not(.primary):not(.danger) { background: rgba(31, 41, 55, 0.96); }
.icon-action.danger::before { content: none; }
.icon-action:disabled { opacity: 0.45; }
.icon-action[data-tip]:hover::after, .icon-action[data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  white-space: pre; font-size: 14px; font-weight: 600; line-height: 1.35; text-align: left;
  background: #0b0e13; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); pointer-events: none; z-index: 1;
}
.swatch.new-gem { border-color: #ff3df0; background: rgba(255, 61, 240, 0.25); box-shadow: 0 0 6px #ff3df0; }

/* ?3d renderer */
.three-mine { position: absolute; inset: 0; overflow: hidden; }
.three-mine canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.three-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.float-num {
  position: absolute; left: 0; top: 0; font: 900 15px system-ui, -apple-system, "PingFang TC", sans-serif; white-space: nowrap;
  -webkit-text-stroke: 4px #141414; paint-order: stroke fill; will-change: transform, opacity;
}
.float-num.big { font-size: 20px; }
.float-num[hidden] { display: none; }
.three-banner {
  position: absolute; left: 0; right: 0; top: 26%; display: grid; place-items: center; gap: 4px; padding: 14px 0;
  background: rgba(0, 0, 0, 0.5); color: #e5e7eb; font: 700 18px system-ui, sans-serif;
}
.three-banner strong { font: 900 44px system-ui, -apple-system, "PingFang TC", sans-serif; -webkit-text-stroke: 6px #111; paint-order: stroke fill; }
.three-banner[hidden] { display: none; }
.three-banner.show { animation: banner 2s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: scaleY(0.2); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
.three-edge { position: absolute; inset: 0; box-shadow: inset 0 0 60px 10px rgba(239, 68, 68, 0.75); opacity: 0; }
.three-edge.flash { animation: edge 0.6s ease; }
@keyframes edge { 0% { opacity: 1; } 100% { opacity: 0; } }
