:root {
  --bg: #f3efe5;
  --panel: #fffaf1;
  --ink: #1f2a31;
  --line: #d8cbb4;
  --accent: #c4572f;
  --accent-2: #2d7a78;
  --shadow: rgba(31, 42, 49, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans JP", "Hiragino Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(196, 87, 47, 0.14), transparent 24%),
    radial-gradient(circle at bottom right, rgba(45, 122, 120, 0.18), transparent 28%),
    linear-gradient(180deg, #f6f2e9, var(--bg));
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 20px;
  padding: 20px;
  min-height: 100vh;
}

.panel {
  background: color-mix(in srgb, var(--panel) 94%, white);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 20px 60px var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.editor-panel {
  height: calc(100dvh - 40px);
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-family: "Avenir Next", "Futura", sans-serif;
  letter-spacing: 0.04em;
}

.lead {
  margin-top: 10px;
  line-height: 1.6;
}

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

.sample-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 2px;
  font-size: 14px;
  color: #6f5d49;
}

.sample-picker select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  background: #fffdf8;
  color: var(--ink);
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

button.ghost {
  background: #e7dbc8;
  color: var(--ink);
}

.editor-shell {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fffdf8;
}

.editor-stage {
  position: relative;
  min-width: 0;
}

.line-numbers {
  padding: 16px 8px 16px 0;
  overflow: hidden;
  text-align: right;
  font: 15px/1.55 "IBM Plex Mono", "SFMono-Regular", monospace;
  color: #967f66;
  background: #f4ede1;
  border-right: 1px solid var(--line);
  user-select: none;
  white-space: pre;
}

.current-line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(15px * 1.55);
  background: rgba(196, 87, 47, 0.1);
  pointer-events: none;
}

.error-line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(15px * 1.55);
  background: rgba(196, 87, 47, 0.2);
  pointer-events: none;
}

#editor {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  padding: 16px;
  resize: none;
  font: 15px/1.55 "IBM Plex Mono", "SFMono-Regular", monospace;
  background: transparent;
  color: #1d2730;
}

#output {
  min-height: 88px;
  margin-top: 12px;
  padding: 14px;
  border-radius: 16px;
  background: #1f2a31;
  color: #eef3f2;
  font: 13px/1.5 "IBM Plex Mono", monospace;
  overflow: auto;
}

.screen-shell {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: 20px auto 0;
}

#screen {
  display: block;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 4 / 3;
  border: 8px solid #1f2a31;
  border-radius: 18px;
  image-rendering: pixelated;
  background: black;
  box-shadow: inset 0 0 0 4px #f5eddc;
}

.screen-dim {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: rgba(120, 128, 136, 0.34);
  z-index: 1;
}

.screen-dim[hidden] {
  display: none;
}

.start-overlay {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 88px;
  height: 88px;
  border-radius: 999px;
  padding: 0;
  background: color-mix(in srgb, var(--accent) 84%, white);
  box-shadow:
    0 18px 38px rgba(31, 42, 49, 0.3),
    inset 0 0 0 4px rgba(255, 250, 241, 0.32);
  display: grid;
  place-items: center;
  z-index: 2;
}

.start-overlay[hidden] {
  display: none;
}

.start-overlay:hover {
  background: color-mix(in srgb, var(--accent) 92%, white);
}

.start-overlay__triangle {
  width: 0;
  height: 0;
  margin-left: 6px;
  border-top: 14px solid transparent;
  border-bottom: 14px solid transparent;
  border-left: 24px solid #fffaf1;
}

.notes {
  margin-top: 18px;
  display: grid;
  gap: 8px;
  line-height: 1.6;
}

.gamepad {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 16px;
  border-radius: 22px;
  background:
    radial-gradient(circle at top left, rgba(229, 106, 63, 0.12), transparent 30%),
    linear-gradient(180deg, #efe4d2, #e6d7bf);
  border: 1px solid #d8cbb4;
  touch-action: none;
}

.gamepad-dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 64px);
  gap: 8px;
  align-items: center;
}

.gamepad-actions {
  display: grid;
  grid-template-columns: repeat(2, 72px);
  gap: 12px;
  align-items: center;
}

.gamepad-spacer {
  width: 64px;
  height: 64px;
}

.pad-btn {
  display: grid;
  place-items: center;
  min-width: 64px;
  min-height: 64px;
  border-radius: 22px;
  padding: 0;
  font-family: "Avenir Next", "Futura", sans-serif;
  font-size: 20px;
  font-weight: 700;
  background: #fff9f1;
  color: #1f2a31;
  box-shadow:
    0 10px 18px rgba(31, 42, 49, 0.12),
    inset 0 -4px 0 rgba(31, 42, 49, 0.08);
}

.pad-space {
  grid-column: 1 / span 2;
  width: 156px;
  height: 64px;
  font-size: 14px;
  letter-spacing: 0.08em;
  background: #2d7a78;
  color: #fff9f1;
}

.pad-action {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  background: #c4572f;
  color: #fff9f1;
}

.pad-btn.is-pressed {
  transform: translateY(2px);
  box-shadow:
    0 4px 10px rgba(31, 42, 49, 0.12),
    inset 0 3px 0 rgba(31, 42, 49, 0.12);
}

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    order: 1;
  }

  .editor-panel {
    order: 2;
    height: auto;
  }

  .editor-shell {
    min-height: 320px;
  }

  .gamepad {
    padding: 14px;
  }

  .gamepad-dpad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(3, 56px);
    gap: 6px;
  }

  .gamepad-actions {
    grid-template-columns: repeat(2, 64px);
    gap: 10px;
  }

  .gamepad-spacer,
  .pad-btn {
    min-width: 56px;
    min-height: 56px;
    width: 56px;
    height: 56px;
  }

  .pad-action {
    width: 64px;
    height: 64px;
  }

  .pad-space {
    width: 138px;
    height: 56px;
  }
}
