:root {
  --bg: #0e1116;
  --panel: rgba(18, 23, 31, 0.96);
  --panel-border: #222d3d;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4c9aff;
  --accent-strong: #2f7ff0;
  --danger: #e5484d;
  --surface: #1a2230;
  --surface-hover: #24303f;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#viewport {
  position: fixed;
  inset: 0;
}

#viewport canvas {
  display: block;
  touch-action: none;
}

/* ---------- Panel ---------- */

#panel {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  width: 288px;
  height: 100%;
  overflow-y: auto;
  padding: 18px 18px 28px;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.3px;
}

.brand h1 span {
  color: var(--accent);
}

.tagline {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.group {
  padding: 12px 0;
  border-top: 1px solid var(--panel-border);
}

.group h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 8px;
}

.row + .row,
.row + select,
select + .row,
input + .row,
#palette + .custom-color {
  margin-top: 8px;
}

/* ---------- Buttons ---------- */

button {
  flex: 1;
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

button:hover:not(:disabled) {
  background: var(--surface-hover);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.mode.active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.accent {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.accent:hover:not(:disabled) {
  background: var(--accent);
}

button.danger {
  color: #ffb4b6;
  border-color: #45262a;
}

button.danger:hover:not(:disabled) {
  background: #3a1f22;
}

/* ---------- Inputs ---------- */

input[type="text"],
select {
  width: 100%;
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  outline: none;
}

input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
}

select {
  margin-top: 8px;
}

/* ---------- Palette ---------- */

.palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: 7px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

.custom-color {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
}

.custom-color input[type="color"] {
  width: 34px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

/* ---------- Footer text ---------- */

.counter {
  margin: 16px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

.counter span {
  color: var(--text);
  font-weight: 700;
}

.hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: #5f6c7e;
}

/* ---------- Hamburger ---------- */

#menu-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  display: none;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
}

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  padding: 10px 18px;
  font-size: 13px;
  color: #fff;
  background: #1f2a3a;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateX(-50%) translateY(16px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Mobile ---------- */

@media (max-width: 820px) {
  #menu-toggle {
    display: block;
  }

  #panel {
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }

  #panel.open {
    transform: translateX(0);
  }
}
