* {
  box-sizing: border-box;
}

:root {
  --bg-dark: #14110d;
  --bg-deep: #0c0907;
  --panel-strong: linear-gradient(180deg, rgba(20, 17, 14, 0.96), rgba(11, 9, 7, 0.98));
  --line: rgba(180, 155, 103, 0.22);
  --line-strong: rgba(180, 155, 103, 0.72);
  --text: #ebe0c8;
  --muted: #aea188;
  --accent: #d6b067;
  --goal: #d45573;
  --build: #82b4d9;
  --danger: #b36552;
  --shadow: rgba(0, 0, 0, 0.58);
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  color: var(--text);
  font-family: Verdana, Geneva, sans-serif;
  background:
    radial-gradient(circle at top, rgba(174, 132, 62, 0.08), transparent 36%),
    radial-gradient(circle at bottom, rgba(88, 69, 45, 0.14), transparent 34%),
    linear-gradient(180deg, #29231d, #0c0907 74%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.015) 0, rgba(255, 255, 255, 0.015) 1px, transparent 1px, transparent 4px),
    radial-gradient(circle at top left, rgba(214, 176, 103, 0.07), transparent 24%),
    radial-gradient(circle at top right, rgba(122, 128, 90, 0.05), transparent 20%);
  opacity: 0.7;
}

button,
canvas {
  font: inherit;
}

.hidden {
  display: none !important;
}

#app {
  position: relative;
  z-index: 1;
  width: min(1840px, calc(100% - 16px));
  height: 100dvh;
  margin: 0 auto;
  padding: 8px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    var(--panel-strong),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.015) 0, rgba(255, 255, 255, 0.015) 1px, transparent 1px, transparent 4px);
  box-shadow:
    0 24px 46px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.topbar {
  padding: 10px 12px;
  display: grid;
  gap: 10px;
}

.title-row,
.toolbar-row,
.action-row,
.meta-strip {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  flex-wrap: wrap;
}

.toolbar-row {
  justify-content: space-between;
}

.title-block {
  display: grid;
  gap: 4px;
}

.title-block h1,
.stage-header h2,
.overlay-header h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 32px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-note,
.overlay-copy {
  color: var(--muted);
  font-size: 12px;
}

.tool-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 420px;
}

.action-row {
  justify-content: flex-end;
  flex: 1 1 420px;
}

.delay-button-row,
.direction-button-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.delay-button,
.direction-button {
  min-height: 34px;
  min-width: 42px;
  padding: 0 10px;
  border-radius: 10px;
}

.delay-button.active,
.direction-button.active {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, rgba(90, 74, 48, 0.98), rgba(44, 36, 24, 1));
  box-shadow:
    inset 0 0 0 1px rgba(214, 176, 103, 0.22),
    0 10px 18px rgba(0, 0, 0, 0.18);
}

.harpoon-delay-popup,
.drive-direction-popup {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  padding: 8px;
  border: 1px solid rgba(180, 155, 103, 0.24);
  border-radius: 14px;
  background: rgba(18, 15, 12, 0.94);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, calc(-100% - 12px));
  pointer-events: auto;
}

.tool-button,
.primary-button,
.secondary-button {
  border: 1px solid rgba(180, 155, 103, 0.24);
  color: var(--text);
  background: linear-gradient(180deg, rgba(60, 52, 44, 0.96), rgba(24, 20, 17, 0.98));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 10px 18px rgba(0, 0, 0, 0.2);
}

.tool-button {
  position: relative;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 14px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.tool-button svg {
  width: 34px;
  height: 34px;
  display: block;
}

.tool-hotkey-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(214, 176, 103, 0.92);
  color: #17120d;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
}

.tool-button.active {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, rgba(74, 63, 49, 0.98), rgba(32, 27, 22, 1));
  box-shadow:
    inset 0 0 0 1px rgba(214, 176, 103, 0.22),
    0 12px 20px rgba(0, 0, 0, 0.24);
}

.tool-button:hover,
.primary-button:hover,
.secondary-button:hover {
  border-color: rgba(180, 155, 103, 0.42);
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(180deg, rgba(102, 82, 47, 0.98), rgba(60, 47, 28, 1));
}

.danger-button {
  border-color: rgba(179, 101, 82, 0.34);
}

button:disabled {
  opacity: 0.44;
  cursor: not-allowed;
}

.stage-panel {
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  overflow: hidden;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.stage-title-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.level-hint {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.2;
  padding-top: 4px;
}

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

.status-pill {
  appearance: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(180, 155, 103, 0.18);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-pill {
  cursor: pointer;
}

.editor-pill:not(:disabled):hover {
  border-color: rgba(180, 155, 103, 0.42);
  background: rgba(255, 255, 255, 0.08);
}

.editor-pill:disabled {
  opacity: 1;
  cursor: default;
}

.muted-pill {
  color: var(--muted);
}

.canvas-shell {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(241, 236, 228, 0.96), rgba(225, 219, 207, 0.96)),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.015) 0, rgba(0, 0, 0, 0.015) 1px, transparent 1px, transparent 5px);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.06),
    inset 0 18px 28px rgba(255, 255, 255, 0.18);
}

#gameCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  background: #f6f1e7;
  touch-action: none;
}

.stage-footer {
  min-height: 22px;
  display: flex;
  align-items: center;
}

.status-text {
  display: block;
  color: var(--muted);
  font-size: 24px;
  line-height: 1.4;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(540px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(180, 155, 103, 0.28);
  background: rgba(18, 15, 12, 0.92);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.3);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(7, 6, 5, 0.74);
  backdrop-filter: blur(10px);
}

.overlay-panel {
  width: min(1220px, 100%);
  max-height: min(860px, calc(100dvh - 32px));
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
}

.overlay-header,
.overlay-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.overlay-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 12px;
}

.overlay-copy {
  margin: 6px 0 0;
}

.level-list {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
  overflow: auto;
  padding-right: 4px;
}

.level-section {
  border: 1px solid rgba(180, 155, 103, 0.18);
  border-radius: 18px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(40, 34, 28, 0.92), rgba(19, 16, 13, 0.94));
}

.level-section-title {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.level-section-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.level-button {
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(180, 155, 103, 0.18);
  background: linear-gradient(180deg, rgba(55, 48, 40, 0.94), rgba(21, 18, 15, 0.96));
  color: var(--text);
  cursor: pointer;
  min-height: 132px;
}

.level-button.active {
  border-color: var(--line-strong);
}

.level-button.locked {
  opacity: 0.42;
}

.level-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.level-button h3 {
  margin: 0;
  font-size: 18px;
}

.level-meta {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.level-score-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.level-score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.level-score-row span {
  color: var(--muted);
}

.level-score-row strong {
  color: var(--text);
}

.scoreboard-card,
.score-card {
  border: 1px solid rgba(180, 155, 103, 0.18);
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(40, 34, 28, 0.92), rgba(19, 16, 13, 0.94));
}

.scoreboard-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.scoreboard-table {
  display: grid;
  gap: 8px;
}

.scoreboard-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1.6fr) minmax(140px, 1fr) minmax(120px, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
}

.scoreboard-row span:nth-child(3),
.scoreboard-row span:nth-child(4) {
  text-align: right;
}

.scoreboard-row-header {
  background: rgba(214, 176, 103, 0.12);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
}

.score-group {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.score-group h3 {
  margin: 0;
  color: var(--accent);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.score-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
}

.score-line strong {
  color: var(--text);
}

.score-line.muted {
  color: var(--muted);
}

.score-line.total-formula {
  border: 1px solid rgba(180, 155, 103, 0.18);
}

.score-total {
  margin-top: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(214, 176, 103, 0.12);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-note {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.score-note.accent {
  color: var(--accent);
}

@media (max-width: 980px) {
  #app {
    width: calc(100% - 12px);
    padding: 6px 0;
    gap: 8px;
  }

  .topbar,
  .stage-panel {
    padding: 8px;
  }

  .tool-button {
    width: 50px;
    height: 50px;
  }

  .tool-button svg {
    width: 30px;
    height: 30px;
  }

  .tool-hotkey-badge {
    top: 3px;
    left: 3px;
    min-width: 16px;
    height: 16px;
    font-size: 9px;
  }

  .primary-button,
  .secondary-button {
    min-height: 38px;
    padding: 0 12px;
  }

  .overlay-panel {
    padding: 14px;
  }

  .level-hint {
    font-size: 11px;
  }

  .status-text {
    font-size: 20px;
  }

  .scoreboard-row {
    grid-template-columns: 52px minmax(0, 1fr) 108px 96px;
    gap: 8px;
    padding: 10px;
    font-size: 12px;
  }
}

/* FC BUILD V6: use SVG as the primary playfield so build parts are always visible. */
.fc-stage-svg {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 20 / 9;
  border-radius: 18px;
  background: #f6f1e7;
  touch-action: none;
  user-select: none;
}
