:root {
  color-scheme: light;
  --ink: #13282c;
  --muted: #516466;
  --paper: #f6efdf;
  --panel: #fffaf0;
  --line: rgba(19, 40, 44, 0.15);
  --accent: #c5533d;
  --builder: #2d756d;
  --stopper: #824b79;
  --shadow: 0 16px 50px rgba(19, 40, 44, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(207, 233, 237, 0.85), rgba(246, 239, 223, 0.92)),
    var(--paper);
}

button,
select,
textarea,
input {
  font: inherit;
}

button,
select {
  min-height: 2.55rem;
}

button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fffaf0;
  font-weight: 800;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  background: transparent;
  color: var(--ink);
}

button:disabled {
  border-color: var(--line);
  background: rgba(19, 40, 44, 0.08);
  color: rgba(19, 40, 44, 0.42);
  cursor: not-allowed;
}

button:disabled:hover {
  background: rgba(19, 40, 44, 0.08);
  color: rgba(19, 40, 44, 0.42);
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(197, 83, 61, 0.26);
  outline-offset: 3px;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem);
  gap: 1rem;
  min-height: 100svh;
  padding: 1rem;
}

.play-area {
  display: grid;
  grid-template-rows: auto minmax(18rem, 1fr) auto;
  gap: 1rem;
  min-width: 0;
}

.topbar,
.control-panel,
.hud,
dialog {
  background: rgba(255, 250, 240, 0.86);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
}

.eyebrow,
.panel-label {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.room-meta,
.button-row,
.dialog-head,
.section-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.room-meta {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.room-meta span + span {
  padding-left: 0.55rem;
  border-left: 1px solid var(--line);
  color: var(--accent);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  min-height: 20rem;
  border: 1px solid rgba(19, 40, 44, 0.22);
  background: #d7ecec;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: min(62svh, 48rem);
}

.end-banner {
  position: absolute;
  inset: auto 1rem 1rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem;
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid var(--line);
}

.end-banner[hidden] {
  display: none;
}

.end-banner strong {
  font-size: 1.1rem;
}

.end-banner span {
  color: var(--muted);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.hud div {
  display: grid;
  gap: 0.2rem;
  padding: 0.85rem;
  background: rgba(255, 250, 240, 0.64);
}

.hud span,
.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.hud strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: calc(100svh - 2rem);
  overflow: auto;
  padding: 1rem;
}

.control-panel section {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.control-panel section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.segmented,
.tool-grid,
.editor-actions,
.editor-budget,
.editor-palette,
.editor-object-actions {
  display: grid;
  gap: 0.45rem;
}

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

.segmented button,
.tool-grid button,
.editor-actions button,
.editor-palette button,
.button-row button {
  background: transparent;
  color: var(--ink);
}

.segmented button.is-active,
.tool-grid button.is-active,
.editor-palette button.is-active,
#submit-report,
.report-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffaf0;
}

.section-head {
  justify-content: space-between;
}

.small-button {
  min-height: 2rem;
  padding: 0.35rem 0.55rem;
  background: transparent;
  color: var(--ink);
  font-size: 0.78rem;
}

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

.editor-budget {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 0.55rem;
}

.editor-budget div {
  min-width: 0;
  padding: 0.55rem 0.62rem;
  border: 1px solid var(--line);
}

.editor-budget span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.editor-budget strong {
  display: block;
  margin-top: 0.14rem;
  font-size: 0.94rem;
}

.editor-budget strong.is-warning {
  color: var(--accent);
}

.editor-palette {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 0.55rem;
}

.editor-palette button {
  min-height: 2.2rem;
  padding: 0.35rem;
  font-size: 0.78rem;
}

.editor-object-actions {
  margin-top: 0.55rem;
}

.editor-object-actions output {
  display: block;
  overflow: hidden;
  min-height: 2.3rem;
  padding: 0.62rem 0.7rem;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 0.35rem;
}

select,
textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

select,
input {
  padding: 0.7rem;
}

textarea {
  min-height: 6rem;
  padding: 0.75rem;
  line-height: 1.35;
  resize: vertical;
}

#level-json {
  min-height: 18rem;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
}

pre {
  overflow: auto;
  max-height: 10rem;
  margin: 0.7rem 0 0;
  padding: 0.7rem;
  background: rgba(19, 40, 44, 0.08);
  white-space: pre-wrap;
}

.role-help p:not(.panel-label),
.fine-print {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.65rem;
  min-height: 1.45rem;
  margin-right: 0.25rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.76rem;
  font-weight: 900;
}

.events {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.community-levels {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.community-levels li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.community-levels strong {
  display: block;
  color: var(--ink);
}

.report-button {
  width: 100%;
}

dialog {
  width: min(38rem, calc(100vw - 2rem));
  padding: 0;
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(19, 40, 44, 0.42);
}

.report-form {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
}

.dialog-head {
  justify-content: space-between;
}

.dialog-head h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 400;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-weight: 700;
}

.check-row input {
  width: 1rem;
}

output {
  min-height: 1.25rem;
  color: var(--accent);
  font-weight: 800;
}

@media (max-width: 62rem) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    max-height: none;
  }

  canvas {
    min-height: 58svh;
  }
}

@media (max-width: 38rem) {
  .game-shell {
    padding: 0.6rem;
  }

  .topbar,
  .hud,
  .end-banner {
    grid-template-columns: 1fr;
  }

  .topbar,
  .end-banner,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  .segmented {
    grid-template-columns: 1fr;
  }
}

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