:root {
  --bg-0: #040a16;
  --bg-1: #071224;
  --bg-2: #0b1c38;
  --bg-3: #10254d;
  --line: #14335e;
  --line-bright: #1e4a8a;
  --cyan: #22d3ee;
  --cyan-soft: #67e8f9;
  --cyan-dim: #0e7490;
  --text: #dbe7ff;
  --text-dim: #8fb2e8;
  --danger: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1100px 700px at 78% -12%, rgba(34, 211, 238, 0.13), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(30, 74, 138, 0.25), transparent 55%),
    var(--bg-0);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 18, 36, 0.85);
  backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 30px; height: 30px; flex: 0 0 auto; filter: drop-shadow(0 0 6px rgba(34, 211, 238, 0.55)); }
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f0f9ff;
  text-shadow: 0 0 14px rgba(34, 211, 238, 0.45);
}
.brand-text p { margin: 0; font-size: 11px; color: var(--text-dim); letter-spacing: 0.06em; }

.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line-bright);
  background: linear-gradient(180deg, rgba(16, 37, 77, 0.9), rgba(11, 28, 56, 0.9));
  color: var(--text);
  border-radius: 9px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); box-shadow: 0 0 12px rgba(34, 211, 238, 0.35); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-icon { width: 34px; padding: 7px 0; text-align: center; font-weight: 700; }
.btn-small { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.active { border-color: var(--cyan); background: rgba(34, 211, 238, 0.16); box-shadow: 0 0 12px rgba(34, 211, 238, 0.4); }
.only-mobile { display: none; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 330px;
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

/* ---------- palette ---------- */
.palette {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 2px;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(16, 37, 77, 0.55), rgba(7, 18, 36, 0.75));
  color: var(--text-dim);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.palette-item svg { width: 30px; height: 30px; }
.palette-item span { font-size: 10.5px; letter-spacing: 0.04em; text-align: center; }
.palette-item:hover, .palette-item.armed {
  border-color: var(--cyan);
  color: #e0f2fe;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.3);
}
.palette-item.armed { background: rgba(34, 211, 238, 0.12); }

/* ---------- board ---------- */
.board-wrap {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-1);
  box-shadow: inset 0 0 60px rgba(4, 10, 22, 0.7);
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.preset-bar {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(7, 18, 36, 0.78);
  backdrop-filter: blur(4px);
  flex-wrap: wrap;
  max-width: calc(100% - 20px);
}
.preset-label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); }

.toast {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92%, 520px);
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  background: rgba(7, 18, 36, 0.92);
  color: #e0f2fe;
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.5), 0 0 16px rgba(34, 211, 238, 0.25);
  pointer-events: none;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(16, 37, 77, 0.5), rgba(7, 18, 36, 0.72));
  padding: 12px 14px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan-soft);
}
.panel h2 .sub { color: var(--text-dim); letter-spacing: 0.05em; text-transform: none; font-weight: 400; }

.wave-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.wave-num {
  width: 82px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line-bright);
  background: var(--bg-1);
  color: #f0f9ff;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.wave-num:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 10px rgba(34, 211, 238, 0.35); }
.wave-unit { color: var(--text-dim); }
.wave-chip {
  width: 26px;
  height: 26px;
  margin-left: auto;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 12px currentColor;
  background: currentColor;
}

.wave-slider { width: 100%; accent-color: var(--cyan); height: 26px; cursor: pointer; }

.spectrum {
  position: relative;
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  margin-top: 2px;
  overflow: visible;
}
.spectrum-marker {
  position: absolute;
  top: -4px;
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: #f0f9ff;
  box-shadow: 0 0 8px rgba(240, 249, 255, 0.9);
  transform: translateX(-50%);
  pointer-events: none;
}

.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--text-dim); }

.guide { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.guide-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-right: 2px;
}

.guide-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 28, 56, 0.55);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-align: left;
  color: var(--text);
  font: inherit;
}
.guide-card:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(34, 211, 238, 0.25); }
.guide-card .wl {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #f0f9ff;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.guide-card .wl small { font-size: 10px; font-weight: 400; color: var(--text-dim); }
.guide-card .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; margin-top: 4px; }
.guide-card .what { font-size: 12.5px; font-weight: 600; color: #e0f2fe; }
.guide-card .note { font-size: 11.5px; color: var(--text-dim); }
.guide-hint { text-align: center; }

/* ---------- status bar ---------- */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 12px;
  min-height: 38px;
  border-top: 1px solid var(--line);
  background: rgba(7, 18, 36, 0.9);
  font-size: 12px;
  color: var(--text-dim);
}
.sel-actions { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sel-actions .btn-small.danger { border-color: #7f1d1d; color: var(--danger); }
.sel-actions .btn-small.danger:hover { border-color: var(--danger); box-shadow: 0 0 10px rgba(248, 113, 113, 0.35); }

/* ---------- help overlay ---------- */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 10, 22, 0.72);
  backdrop-filter: blur(4px);
}
.help-overlay[hidden] {
  display: none !important;
}
.help-card .btn {
  min-height: 44px;
  min-width: 96px;
  touch-action: manipulation;
}
.help-card {
  max-width: 560px;
  max-height: 86vh;
  overflow-y: auto;
  border: 1px solid var(--line-bright);
  border-radius: 14px;
  background: var(--bg-1);
  padding: 20px 22px;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6), 0 0 30px rgba(34, 211, 238, 0.18);
}
.help-card h2 { margin: 0 0 10px; color: var(--cyan-soft); letter-spacing: 0.08em; }
.help-card ul { margin: 0 0 10px; padding-left: 18px; }
.help-card li { margin-bottom: 7px; }
.help-card kbd {
  padding: 1px 5px;
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  background: var(--bg-2);
  font-size: 11px;
}

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-bright); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- mobile ---------- */
@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); padding: 8px; gap: 8px; }
  .palette {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }
  .palette-item { flex: 0 0 auto; width: 76px; padding: 8px 4px 6px; }
  .palette-item svg { width: 26px; height: 26px; }
  .brand-text p { display: none; }
  .only-mobile { display: inline-block; }
  .side {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(88vw, 350px);
    z-index: 50;
    padding: 12px;
    background: rgba(7, 18, 36, 0.96);
    border-left: 1px solid var(--line-bright);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.55);
    transform: translateX(106%);
    transition: transform 0.24s ease;
  }
  .side.open { transform: none; }
  .topbar { padding: 8px 10px; }
  .top-actions .btn { padding: 7px 9px; font-size: 12px; }
}
