:root {
  --bg: #0f1314;
  --panel-bg: #161b1d;
  --panel-border: #232a2c;
  --text: #e6ecec;
  --muted: #8a9499;
  --accent: #3ddc4a;
  --accent-dim: #1f9a2c;
  --danger: #e64545;
  --warn: #caa07a;
  --btn-bg: #1f2628;
  --btn-bg-hover: #2a3336;
  --btn-border: #2f3a3c;
}

* { box-sizing: border-box; }

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

#app {
  display: grid;
  grid-template-columns: 1fr 320px;
  height: 100vh;
  width: 100vw;
}

/* ---------- Board ---------- */
#boardWrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 40%, #14191b 0%, #0a0d0e 80%);
  overflow: hidden;
}

#board {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.paused-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 18px 40px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(15, 19, 20, 0.78);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  pointer-events: none;
  user-select: none;
  backdrop-filter: blur(2px);
}

.paused-overlay.hidden { display: none; }

/* ---------- Panel ---------- */
#panel {
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#title h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.04em;
}
#title .subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Controls ---------- */
#controls { display: flex; flex-direction: column; gap: 12px; }

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

button {
  flex: 1;
  padding: 8px 10px;
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--btn-border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: var(--btn-bg-hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.field span { display: flex; justify-content: space-between; }

select, input[type="range"] {
  width: 100%;
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--btn-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
input[type="range"] { padding: 0; }

/* ---------- HUD ---------- */
#hud h2, #legend h2, #rules h2, #rules h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
#rules h3 { margin-top: 12px; font-size: 12px; }

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px dashed var(--panel-border);
  font-size: 13px;
}
.stat span { color: var(--muted); }
.stat b { font-variant-numeric: tabular-nums; }

/* ---------- Legend ---------- */
#legend { display: flex; flex-direction: column; gap: 6px; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.legend-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

/* ---------- Rules ---------- */
#rules ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
#rules li { margin-bottom: 3px; }
#rules b { color: var(--text); }
.hotkeys { list-style: none; padding-left: 0; }
kbd {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text);
}

/* ---------- Tooltip ---------- */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  z-index: 100;
  white-space: pre-line;
  line-height: 1.4;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: translate(15px, 15px); /* Offset from cursor */
}

/* ---------- Scrollbar ---------- */
#panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-track { background: transparent; }
#panel::-webkit-scrollbar-thumb {
  background: var(--btn-border);
  border-radius: 4px;
}

/* ---------- Effects ---------- */
@keyframes shake {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(3px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(3px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shake {
  animation: shake 0.5s;
  animation-iteration-count: 2; /* 1 second of shaking */
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #panel { border-left: none; border-top: 1px solid var(--panel-border); max-height: 45vh; }
}
