:root {
  color-scheme: light;
  --paper: #f5f1e7;
  --ink: #181611;
  --muted: #665f51;
  --line: #cfc4aa;
  --panel: #fffaf0;
  --sun: #e7b33e;
  --leaf: #4c8f62;
  --brick: #a94936;
  --screen: #070805;
  --screen-line: #28351e;
  --shadow: 0 18px 48px rgba(47, 38, 20, .15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Pretendard", "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
label,
input {
  font: inherit;
}

button,
label.add-game,
.button-stack label {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
label.add-game:hover,
.button-stack label:hover {
  border-color: var(--brick);
}

button.is-active {
  border-color: var(--leaf);
  background: #e2f0dd;
}

button.primary {
  background: var(--sun);
  border-color: #ba7f18;
  font-weight: 800;
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.shell {
  width: min(1480px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #191814;
  color: #f2c65b;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 3px #3d3320;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 3px;
  font-size: 26px;
}

h2 {
  font-size: 17px;
  margin-bottom: 10px;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.topbar p {
  margin-bottom: 0;
}

.top-actions,
.mode-grid,
.button-stack,
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stage-band {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 340px;
  gap: 12px;
  align-items: stretch;
}

.game-rail,
.side-panel,
.info-band article {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, .76);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-rail {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 620px;
}

.game-list {
  display: grid;
  gap: 8px;
}

.game-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fffcf5;
  text-align: left;
  cursor: pointer;
}

.game-card.is-active {
  border-color: var(--leaf);
  box-shadow: inset 0 0 0 2px rgba(76, 143, 98, .2);
}

.game-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: #171510;
  display: block;
  margin-bottom: 7px;
}

.game-card strong,
.game-card span {
  display: block;
}

.game-card span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.add-game {
  margin-top: auto;
  width: 100%;
}

.screen-wrap {
  position: relative;
  min-height: 620px;
  border-radius: 8px;
  border: 1px solid #272218;
  background:
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px),
    var(--screen);
  background-size: 24px 24px;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: none;
}

.starter {
  width: min(760px, calc(100% - 36px));
  display: grid;
  grid-template-columns: minmax(180px, 320px) 1fr;
  gap: 18px;
  align-items: center;
  color: #f7f0d9;
}

.starter img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #4e422a;
}

.starter h2 {
  font-size: 30px;
}

.starter p {
  color: #d3c7a8;
}

.dos-screen {
  width: min(100%, 980px);
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}

.dos-screen canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  user-select: none;
}

.control-pad {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.control-pad.is-hidden {
  display: none;
}

.v-control {
  position: absolute;
  border: 1px solid rgba(255, 245, 216, .65);
  border-radius: 8px;
  background: rgba(22, 18, 10, .58);
  color: #fff3c9;
  min-height: 0;
  padding: 0;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .25);
}

.v-control.is-pressed {
  background: rgba(231, 179, 62, .82);
  color: #17120a;
}

.v-control.is-editing {
  outline: 2px dashed #f3d16b;
}

.mouse-pad {
  position: absolute;
  right: 18px;
  top: 18px;
  width: min(240px, 34vw);
  height: min(180px, 26vw);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 8px;
  background: rgba(245, 241, 231, .12);
  color: #f5f1e7;
  display: grid;
  place-items: center;
  z-index: 4;
  touch-action: none;
}

.pointer-dot {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ffd14d;
  background: rgba(255, 209, 77, .2);
  box-shadow: 0 0 0 4px rgba(0,0,0,.25), 0 0 18px rgba(255,209,77,.6);
  z-index: 6;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.side-panel {
  padding: 12px;
  min-height: 620px;
  overflow: auto;
}

.status-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  padding: 11px;
  margin-bottom: 10px;
}

.status-card span {
  color: var(--muted);
  font-size: 13px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 10px;
}

.panel-block {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}

.compact {
  display: grid;
  gap: 8px;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.field input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #fffdf7;
  color: var(--ink);
}

.button-stack {
  display: grid;
}

.button-stack.two {
  grid-template-columns: 1fr 1fr;
}

.slot-list {
  display: grid;
  gap: 8px;
}

.slot-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  padding: 7px;
}

.slot-row span {
  color: var(--muted);
  font-size: 12px;
}

.slot-row button {
  min-height: 32px;
  padding: 5px 8px;
}

.editor-actions {
  margin-top: 10px;
}

.editor-actions button {
  min-height: 34px;
  padding: 5px 8px;
}

.hint {
  font-size: 13px;
  margin: 10px 0 0;
}

.log-block pre {
  margin: 0;
  min-height: 104px;
  max-height: 210px;
  overflow: auto;
  background: #181611;
  color: #f5df9e;
  border-radius: 7px;
  padding: 10px;
  white-space: pre-wrap;
  font-size: 12px;
}

.info-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.info-band article {
  padding: 14px;
}

details summary {
  cursor: pointer;
  font-weight: 800;
}

@media (max-width: 1180px) {
  .stage-band {
    grid-template-columns: 160px minmax(0, 1fr);
  }

  .side-panel {
    grid-column: 1 / -1;
    min-height: 0;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 12px, 760px);
    padding-top: 8px;
  }

  .topbar,
  .brand {
    align-items: flex-start;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .top-actions button {
    padding: 6px 5px;
    font-size: 13px;
  }

  h1 {
    font-size: 22px;
  }

  .stage-band,
  .info-band {
    grid-template-columns: 1fr;
  }

  .game-rail {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .screen-wrap {
    min-height: 72vh;
  }

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

  .starter h2 {
    font-size: 24px;
  }

  .mouse-pad {
    top: 12px;
    right: 12px;
    width: 42vw;
    height: 30vw;
  }
}
