* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --space-950: #030611;
  --space-900: #060b1b;
  --space-850: #091225;
  --space-800: #0d1930;
  --panel: rgba(10, 21, 43, 0.94);
  --panel-soft: rgba(14, 29, 57, 0.8);
  --line: #20375a;
  --line-bright: #34557e;
  --text: #e9f8ff;
  --muted: #8ea8c7;
  --subtle: #647d9e;
  --cyan: #42ddff;
  --cyan-soft: #16a9d4;
  --violet: #a878ff;
  --violet-deep: #5526a8;
  --danger: #ff719c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}

html {
  min-width: 320px;
  background: var(--space-950);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -15%, #172851 0, transparent 42rem),
    radial-gradient(circle at 9% 48%, rgba(42, 55, 130, 0.13), transparent 28rem),
    var(--space-950);
  color: var(--text);
  font: 13px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.035em;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  opacity: 0.22;
  pointer-events: none;
  content: "";
  background-image: radial-gradient(#8ea8c7 0.6px, transparent 0.7px);
  background-size: 39px 39px;
  mask-image: linear-gradient(to bottom, #000, transparent 75%);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  background: linear-gradient(180deg, #132643, #0b1830);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: var(--cyan-soft);
  background: #123052;
  box-shadow: 0 0 18px rgba(41, 216, 255, 0.12);
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
.brand:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

button:disabled {
  color: #687b97;
  border-color: #182945;
  background: #0a1326;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.65;
}

.topbar {
  display: flex;
  min-height: 68px;
  align-items: center;
  gap: 30px;
  padding: 12px clamp(16px, 3vw, 38px);
  border-bottom: 1px solid #1b3150;
  background: rgba(6, 13, 29, 0.9);
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-decoration: none;
  white-space: nowrap;
}

.brand span {
  color: var(--cyan);
  font-size: 24px;
  line-height: 1;
  text-shadow: 0 0 15px rgba(66, 221, 255, 0.8);
}

.resources {
  display: flex;
  gap: clamp(12px, 2vw, 28px);
}

.resources div {
  min-width: 64px;
}

.resources b {
  display: block;
  color: #f6fdff;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.resources small,
.world-name small {
  display: block;
  margin-top: 2px;
  color: var(--subtle);
  font-size: 9px;
  letter-spacing: 0.1em;
}

.world-name {
  margin-left: auto;
  color: #c5d9ee;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.layout {
  display: grid;
  max-width: 1500px;
  grid-template-columns: minmax(190px, 220px) minmax(360px, 1fr) minmax(210px, 245px);
  gap: clamp(12px, 2vw, 24px);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px);
}

.panel {
  align-self: start;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(155deg, rgba(14, 31, 61, 0.96), var(--panel));
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 17px;
  color: var(--cyan);
  font-size: 11px;
  letter-spacing: 0.13em;
}

.panel h3 {
  margin: 26px 0 0;
  padding-top: 16px;
  border-top: 1px solid #1b3354;
  color: var(--violet);
  font-size: 9px;
  letter-spacing: 0.12em;
}

.tool-list {
  display: grid;
  gap: 7px;
}

.tool {
  width: 100%;
  color: #adc3dc;
  text-align: left;
}

.tool span {
  margin-left: 8px;
}

.tool.active,
.tool[aria-pressed="true"] {
  border-color: var(--cyan);
  color: #fff;
  background: linear-gradient(100deg, #075079, #12345d);
  box-shadow: 0 0 17px rgba(18, 188, 229, 0.2), inset 3px 0 var(--cyan);
}

.panel label {
  display: block;
  margin-top: 20px;
  color: #b6cce2;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
}

.panel output {
  float: right;
  color: #f5fbff;
  font-variant-numeric: tabular-nums;
}

.panel input[type="range"] {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

.panel select {
  float: right;
  max-width: 54%;
  border: 1px solid #2a4669;
  border-radius: 4px;
  padding: 4px 6px;
  color: var(--text);
  background: #101f3a;
}

.hint {
  margin: 22px 0 0;
  color: var(--subtle);
  font-size: 10px;
  line-height: 1.6;
}

.stage {
  min-width: 0;
  text-align: center;
}

.canvas-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid #2b4d79;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 45%, #122b55, #030713 70%);
  box-shadow: 0 0 0 1px rgba(66, 221, 255, 0.06), 0 0 45px rgba(27, 128, 190, 0.13), var(--shadow);
}

.canvas-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  touch-action: none;
}

.stage-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 12px 0 7px;
}

.stage-controls button {
  min-width: 38px;
  min-height: 34px;
  padding: 6px 10px;
}

#zoomValue {
  min-width: 49px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status {
  min-height: 20px;
  margin: 7px 0;
  color: #91b1d0;
  font-size: 11px;
}

.footer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 70px;
  padding: 12px clamp(16px, 3vw, 38px);
  border-top: 1px solid #1b3150;
  background: rgba(6, 13, 29, 0.94);
}

.footer button {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.finalize {
  border-color: #b88aff;
  padding-inline: 25px;
  background: linear-gradient(105deg, #6326b5, #2934b6);
  box-shadow: 0 0 20px rgba(126, 70, 229, 0.2);
}

.finalize:hover {
  border-color: #dfc8ff;
  background: linear-gradient(105deg, #7935d3, #3544d0);
}

.finalize:disabled {
  border-color: #564d75;
  background: #221c3b;
}

.score-card {
  margin-left: auto;
  padding-left: 20px;
  border-left: 1px solid #294363;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.09em;
}

.score-card strong {
  margin-left: 12px;
  color: #fff;
  font-size: 23px;
  letter-spacing: 0;
}

.score-card small {
  display: block;
  margin-top: 2px;
  color: var(--subtle);
  letter-spacing: 0.03em;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 185px minmax(300px, 1fr) 200px;
    gap: 12px;
    padding: 16px;
  }

  .topbar {
    gap: 18px;
  }

  .resources {
    gap: 12px;
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    padding: 11px 14px;
  }

  .world-name {
    display: none;
  }

  .resources {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .layout {
    display: flex;
    flex-direction: column;
    padding: 12px;
  }

  .stage {
    order: 1;
  }

  .tools {
    order: 2;
  }

  .settings {
    order: 3;
  }

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

  .panel {
    padding: 14px;
  }

  .settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
  }

  .settings h2,
  .settings h3 {
    grid-column: 1 / -1;
  }

  .settings h3 {
    margin-top: 18px;
  }

  .footer {
    flex-wrap: wrap;
    padding: 11px 14px;
  }

  .finalize {
    flex: 1 1 180px;
  }

  .score-card {
    width: 100%;
    margin: 0;
    padding: 8px 0 0;
    border: 0;
    text-align: center;
  }
}

@media (max-width: 430px) {
  .brand {
    font-size: 12px;
  }

  .resources div {
    min-width: 0;
  }

  .resources b {
    font-size: 13px;
  }

  .settings {
    display: block;
  }

  .settings h3 {
    margin-top: 23px;
  }

  .footer button {
    flex: 1 1 auto;
    padding-inline: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
