:root {
  /* Tool-specific aliases */
  --accent-strong: #ecd49a;
  --accent-deep: #c4a85e;
  --accent-soft: rgba(226, 200, 126, 0.15);
  --danger: #d45a5a;
  --border-strong: rgba(100, 114, 83, 0.5);

  /* Font alias (variables.css defines --font-sans, not --font-body) */
  --font-body: var(--font-sans);

  /* Grid drawing colors (for SVG elements on white board) */
  --grid-color: rgba(29, 26, 22, 0.35);
  --grid-light: rgba(29, 26, 22, 0.4);

  /* Layout helpers (used by app.js edge controls) */
  --side-control-width: 2rem;
  --side-control-gap: 0.15rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  position: relative;
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
  font-family: var(--font-body);
  color: var(--color-text);
  background:
    radial-gradient(circle at 14% -8%, rgba(226, 200, 126, 0.08), transparent 45%),
    radial-gradient(circle at 86% 8%, rgba(122, 138, 90, 0.1), transparent 32%),
    var(--color-bg);
}

/* --- App Shell & Header --- */

.app-shell {
  display: contents;
}

.app-header {
  background: rgba(31, 40, 27, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-line);
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
}

.title-block {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: linear-gradient(150deg, var(--color-surface-alt), var(--color-surface));
  box-shadow: var(--shadow-sm);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  animation: float-in 0.6s ease both;
}

.title-block h1 {
  font-family: var(--font-heading);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  margin: 0;
}

.back-link {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

.back-link:hover {
  color: var(--accent-deep);
  text-decoration: underline;
}

.subtitle {
  display: none;
}

/* --- Main Layout --- */
/* (legacy rule removed; see consolidated definition below) */

/* --- Panels --- */

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem 1.4rem 1.6rem;
  display: grid;
  gap: 1.1rem;
  animation: float-in 0.7s ease both;
}

.panel-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.panel-block .panel-title {
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--color-line);
}

.control-panel {
  position: static;
  width: clamp(200px, 18vw, 320px);
  overflow-y: auto;
  max-height: 100%;
}

.app-main {
  grid-row: 2;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-xs);
  padding: var(--space-sm);
  overflow: hidden;
  min-height: 0;
}

.workspace-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  gap: var(--space-xs);
  background: transparent;
  border: none;
  box-shadow: none;
  padding: var(--space-xs) 0;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: calc(var(--side-control-width) + var(--side-control-gap));
}

.board-shell {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 297 / 210;
  overflow: visible;
}

.board-stack {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.right-panels-col {
  width: clamp(180px, 16vw, 260px);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  overflow-y: auto;
  max-height: 100%;
}

.section-kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.active-tool-label {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
  background: rgba(226, 200, 126, 0.12);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  min-height: 1.6rem;
  display: flex;
  align-items: center;
  transition: opacity 0.15s ease;
}

.active-tool-label:empty {
  opacity: 0;
}

.workspace-meta {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.workspace-meta--header {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(42rem, calc(100vw - 2rem));
  margin: 0;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 0;
  min-width: 0;
}

.workspace-meta--header .status-notes {
  min-height: 0;
  min-width: min(26rem, 46vw);
  max-width: min(42rem, 60vw);
}

.workspace-meta--header .status-message {
  min-height: 1.8rem;
  max-height: 1.8rem;
  -webkit-line-clamp: 1;
  padding: 0.18rem 0.45rem;
}

.status-notes {
  display: grid;
  gap: 0.5rem;
  min-height: 2.3rem;
  min-width: min(32rem, 100%);
}

.message {
  color: var(--color-accent);
  font-weight: 600;
  min-height: 0;
}

.status-message {
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  background: rgba(226, 200, 126, 0.1);
  border: 1px solid var(--color-accent);
  min-height: 2.8rem;
  max-height: 2.8rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
  overflow: hidden;
  white-space: normal;
  text-overflow: ellipsis;
}

/* --- Keyboard Hints --- */

.keyboard-hints {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: var(--color-text-muted);
  padding: 0.3rem 0;
}

.keyboard-hints kbd {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--color-line);
  color: var(--color-text);
  line-height: 1;
}

.hint-sep {
  display: inline-block;
  width: 1px;
  height: 0.9em;
  background: var(--border-strong);
  margin: 0 0.15rem;
}

.hint-muted {
  font-style: italic;
  opacity: 0.8;
}

/* --- Panel Blocks & Button Layout --- */

.panel-block {
  display: grid;
  gap: 0.8rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px dashed var(--color-line);
}

.panel-block:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.button-stack,
.button-grid {
  display: grid;
  gap: 0.6rem;
}

.slider-stack {
  display: grid;
  gap: 0.5rem;
}

.slider-stack input[type="range"] {
  width: 100%;
  accent-color: var(--color-accent);
}

.slider-value {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.button-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-grid .wide-button {
  grid-column: 1 / -1;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  font-size: 1rem;
}

.button-stack button,
.button-grid button {
  width: 100%;
  text-align: center;
}


/* --- Edge Controls --- */

.edge-controls {
  position: absolute;
  left: calc(
    var(--board-left) - var(--side-control-gap) - var(--side-control-width)
  );
  top: var(--board-top);
  width: calc(
    var(--board-width) +
      var(--side-control-gap) +
      var(--side-control-width) +
      var(--side-control-gap) +
      var(--side-control-width)
  );
  height: var(--board-height);
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  pointer-events: none;
  z-index: 5;
}

.edge-controls-side {
  width: var(--side-control-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  height: 100%;
  pointer-events: auto;
}

.edge-controls button {
  pointer-events: auto;
}

.wrap-button {
  align-self: stretch;
  min-width: 2rem;
  padding: 0.4rem 0.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  flex: 1;
  background: rgba(226, 200, 126, 0.08);
  border: 1px dashed var(--color-accent);
  color: var(--color-accent);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.wrap-button:hover:not(:disabled) {
  background: rgba(226, 200, 126, 0.18);
  border-style: solid;
}

.wrap-button.active {
  background: linear-gradient(145deg, var(--color-accent), #c4a85e);
  color: var(--color-bg);
  border-style: solid;
}

.wrap-button:disabled {
  opacity: 0.3;
  border-color: var(--color-line);
  color: var(--color-text-muted);
  background: transparent;
}

/* --- SVG Board Layers --- */

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 0;
  border: none;
}

#board.pencil-active {
  cursor: crosshair;
}

.board-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  pointer-events: none;
  z-index: 2;
  touch-action: none;
  border-radius: 0;
}

.marker-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  pointer-events: none;
  z-index: 3;
  touch-action: none;
  border-radius: 0;
}

body[data-tool="paint-continent"] .board-overlay,
body[data-tool="paint-divide"] .board-overlay {
  pointer-events: auto;
}

body[data-tool="crust"] .marker-overlay,
body[data-tool="plate-id"] .marker-overlay,
body[data-tool="direction"] .marker-overlay,
body[data-tool="volcano"] .marker-overlay,
body[data-tool="move-icon"] .marker-overlay {
  pointer-events: auto;
}

/* --- Buttons --- */

button {
  position: relative;
  border: none;
  padding: 0.7rem 1.12rem;
  border-radius: 10px;
  font-weight: 600;
  font-family: var(--font-body);
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease,
    color 0.15s ease, border-color 0.15s ease;
}

button.primary {
  background: linear-gradient(145deg, var(--color-accent), #c4a85e);
  color: var(--color-bg);
  border: none;
  box-shadow: var(--shadow-sm);
}

button.primary:hover {
  transform: translateY(-1px);
}

button.secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-line);
}

button.secondary:hover {
  background: rgba(226, 200, 126, 0.1);
}

button.secondary.active {
  background: linear-gradient(145deg, var(--color-accent), #c4a85e);
  color: var(--color-bg);
  box-shadow: 0 0 0 2px var(--color-accent);
}

button.secondary.active::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 13px;
  border: 2px solid var(--color-accent);
  opacity: 0.5;
  pointer-events: none;
}

button.ghost {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-line);
  color: var(--color-text-muted);
}

button.danger {
  color: #d45a5a;
  border: 1px solid rgba(212, 90, 90, 0.4);
  background: rgba(212, 90, 90, 0.08);
}

button:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  filter: grayscale(0.3);
}

/* --- SVG Drawing Elements --- */

.grid-line {
  stroke: var(--grid-light);
  stroke-width: 0.25;
  vector-effect: non-scaling-stroke;
}

.grid-border {
  stroke: var(--grid-color);
  stroke-width: 0.9;
  fill: none;
  vector-effect: non-scaling-stroke;
}

.cell-dot {
  fill: #000;
}

.cell-asterisk {
  fill: none;
  stroke: #000;
  stroke-linecap: round;
}

.plate-node-active {
  fill: none;
  stroke: #000;
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
}

.pencil-line {
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.pencil-line.plate-boundary {
  stroke: rgba(29, 26, 22, 0.6);
  stroke-width: 0.43;
}

.pencil-line.plate-divergent {
  stroke: rgba(14, 12, 10, 0.95);
  stroke-width: 0.72;
}

.pencil-line.plate-convergent-base {
  stroke: rgba(29, 26, 22, 0.6);
  stroke-width: 0.43;
}

.pencil-line.plate-convergent-zigzag {
  fill: none;
  stroke: rgba(14, 12, 10, 0.98);
  stroke-width: 0.74;
}

.pencil-line.plate-oblique-curve {
  fill: none;
  stroke: rgba(14, 12, 10, 0.97);
  stroke-width: 0.72;
}

.arrow-line {
  stroke: rgba(14, 12, 10, 0.96);
  stroke-width: 0.92;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.divide-line {
  stroke: rgba(14, 12, 10, 0.96);
  stroke-width: 1;
  stroke-dasharray: 6 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.marker-text {
  /* always dark for legibility on white board */
  fill: #1d1a16;
  font-family: var(--font-body);
  font-weight: 600;
  user-select: none;
}

.marker-text.selected {
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 1.05;
  paint-order: stroke;
}

/* --- Animation --- */

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* simplified responsive behavior: require at least 960px width */

@media (max-width: 960px) {
  body {
    min-width: 960px;
  }
}

/* Scrollbar styling (matched to dark theme) */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--color-olive-deep); }
::-webkit-scrollbar-thumb { background: var(--color-line); border-radius: 3px; }
/* --- Accessibility: Reduced Motion --- */

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
