/* Quail Works — grid factory, QUAIL UNIVERSAL palette. */

:root {
  --accent: #0073ff;
  --gold: #ffc247;
  --bg: #05070d;
  --surface: #0d1320;
  --surface-2: #121a2b;
  --card: #0d111d;
  --border: #182238;
  --border-strong: #24324e;
  --text: #e8ecf4;
  --sub: #9aa3b8;
  --dim: #6d7488;
  --good: #28c86e;
  --warn: #ffa23c;
  --bad: #f03c46;
  --r: 9px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

body { height: 100dvh; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- top ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: max(8px, env(safe-area-inset-top)) max(13px, env(safe-area-inset-right)) 8px max(13px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  z-index: 5;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700; letter-spacing: .06em; font-size: .78rem;
  white-space: nowrap;
}

.mark {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 6px; background: var(--accent); color: #fff; font-size: .85rem;
}

.counters { display: flex; gap: 16px; font-size: .82rem; }
.counters b { color: var(--gold); font-variant-numeric: tabular-nums; }
.top-actions { display: flex; gap: 6px; margin-left: auto; }

.mini {
  min-height: 27px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface-2); color: var(--sub);
  font-size: .72rem; font-weight: 600;
}

.mini:hover { color: var(--text); border-color: var(--accent); }
.mini.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.mini.danger:hover { border-color: var(--bad); color: var(--bad); }

/* ---------- stage ---------- */

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#c { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
#c.is-panning { cursor: grabbing; }

.inspect {
  position: absolute;
  pointer-events: none;
  padding: 7px 10px;
  border-radius: 7px;
  background: rgba(5, 7, 13, .93);
  border: 1px solid var(--border-strong);
  font-size: .72rem;
  line-height: 1.55;
  z-index: 6;
  max-width: 220px;
}

.inspect b { color: var(--gold); }
.inspect .ok { color: var(--good); }
.inspect .no { color: var(--warn); }

.hint {
  position: absolute;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(5, 7, 13, .9);
  border: 1px solid var(--border-strong);
  font-size: .76rem;
  color: var(--sub);
  z-index: 6;
  max-width: 90%;
  text-align: center;
}

.hint b { color: var(--text); }

/* ---------- palette ---------- */

.palette {
  display: flex;
  gap: 7px;
  padding: 9px max(12px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  flex-shrink: 0;
  z-index: 5;
}

.tool {
  flex: 0 0 auto;
  width: 84px;
  padding: 8px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--card);
  text-align: center;
  position: relative;
  transition: border-color .13s, transform .1s, background .13s;
}

.tool:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.tool.is-on { border-color: var(--accent); background: rgba(0, 115, 255, .16); }
.tool:disabled { opacity: .35; cursor: not-allowed; }

.tool-ico { display: block; font-size: 1.35rem; line-height: 1.2; }
.tool-name { display: block; font-size: .67rem; font-weight: 700; margin-top: 2px; }
.tool-cost { display: block; font-size: .64rem; color: var(--gold); margin-top: 1px; font-variant-numeric: tabular-nums; }

.tool-key {
  position: absolute;
  left: 4px; top: 3px;
  font-size: .56rem;
  color: var(--dim);
  font-weight: 800;
}

/* ---------- research ---------- */

.tech {
  position: absolute;
  right: 12px;
  top: 58px;
  width: 268px;
  max-height: calc(100% - 180px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: rgba(13, 19, 32, .96);
  backdrop-filter: blur(6px);
  z-index: 7;
  overflow: hidden;
}

.tech.is-min .tech-list { display: none; }

.tech-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--dim);
}

.tech-list { overflow-y: auto; }

.t {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 9px;
  width: 100%;
  padding: 10px 11px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  text-align: left;
  align-items: start;
}

.t:hover:not(:disabled) { background: var(--surface-2); }
.t:disabled { opacity: .45; cursor: not-allowed; }
.t.done { opacity: .5; }
.t-ico { font-size: 1rem; text-align: center; }
.t-name { display: block; font-weight: 650; font-size: .78rem; }
.t-desc { display: block; font-size: .68rem; color: var(--sub); margin-top: 2px; line-height: 1.45; }
.t-cost { display: inline-block; margin-top: 4px; font-size: .67rem; font-weight: 700; color: var(--gold); }
.t.done .t-cost { color: var(--good); }

/* ---------- modal ---------- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  place-items: center;
  background: rgba(5, 7, 13, .82);
  backdrop-filter: blur(4px);
}

.modal.is-open { display: grid; }

.modal-box {
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.modal-box h2 { margin: 0 0 10px; font-family: "Space Grotesk", sans-serif; font-size: 1.25rem; }
.modal-box p { margin: 0 0 16px; color: var(--sub); font-size: .84rem; line-height: 1.65; }

.keys { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.keys th { text-align: left; padding: 6px 10px 6px 0; font-size: .76rem; color: var(--text); white-space: nowrap; vertical-align: top; }
.keys td { padding: 6px 0; font-size: .78rem; color: var(--sub); }

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--card);
  font-family: ui-monospace, monospace;
  font-size: .72rem;
}

.chain {
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: .76rem !important;
  line-height: 1.8 !important;
}

.modal-actions { display: flex; justify-content: flex-end; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%);
  padding: 10px 19px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: .8rem; font-weight: 600;
  z-index: 40;
  animation: toastIn .22s ease;
  max-width: 86vw; text-align: center;
}

.toast.gold { border-color: var(--gold); color: var(--gold); }
.toast.bad { border-color: var(--bad); color: var(--bad); }

@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (max-width: 760px) {
  .tech { width: 210px; top: 52px; right: 8px; }
  .counters { gap: 10px; font-size: .74rem; }
  .tool { width: 72px; }
}

/* ---------- touch screens ---------- */

.mini .ico { display: none; }
.touch-only { display: none; }

.touchbar {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 6;
}

.tb {
  width: 56px;
  min-height: 56px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  padding: 5px 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: rgba(13, 19, 32, .92);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1.1;
}

.tb small { font-size: .58rem; font-weight: 700; color: var(--sub); }
.tb[aria-pressed="true"] { border-color: var(--accent); background: rgba(0, 115, 255, .3); }
.tb[aria-pressed="true"] small { color: var(--text); }
#tbArrow { display: inline-block; transition: transform .15s; }

body.touch .touch-only { display: table; }
body.touch .mouse-only { display: none; }
body.touch #c { cursor: default; }
body.touch .mini { min-height: 44px; min-width: 44px; font-size: .78rem; }
body.touch .tool { min-height: 64px; }
body.touch .tool:hover:not(:disabled) { transform: none; }
body.touch .tool-key { display: none; }
body.touch .t { min-height: 48px; }
body.touch .hint { cursor: pointer; }
body.touch .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
body.touch .modal-box { max-height: 86dvh; }
body.touch .tech { top: calc(max(8px, env(safe-area-inset-top)) + 62px); right: max(8px, env(safe-area-inset-right)); max-height: calc(100% - 210px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }

@media (max-width: 640px) {
  .topbar { gap: 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .brand-name { display: none; }
  .counters { gap: 10px; font-size: .78rem; white-space: nowrap; }
  .top-actions { gap: 5px; }
  .mini .ico { display: inline; font-size: .95rem; }
  .mini .lbl { display: none; }
  .mini { padding: 0 9px; }
  .tech { width: min(240px, calc(100% - 84px)); }
  .hint { bottom: 8px; font-size: .72rem; padding: 7px 12px; border-radius: 12px; }
}

@media (max-width: 380px) {
  .counters span:nth-child(3) { display: none; }
}
