:root {
  --ink: #140c18;
  --ink-2: #22162c;
  --parchment: #f4e7c8;
  --gold: #e6c36a;
  --crimson: #d94c3a;
  --azure: #3a7ad9;
  --muted: #b9a58c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  background: radial-gradient(circle at 50% 0%, #2a1b38, var(--ink) 55%);
  color: var(--parchment);
  min-height: 100vh;
}

a { color: var(--gold); }
h1, h2 { font-weight: 600; letter-spacing: 0.04em; margin: 0.2em 0; }
.eyebrow { color: var(--gold); text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.75rem; margin: 0; }
.tag { font-style: italic; color: var(--muted); margin-top: 0; }
.wrap { max-width: 720px; margin: 0 auto; padding: 48px 20px 80px; }
.hero { text-align: center; }
.hero h1 { font-size: 3rem; }
.cta {
  display: inline-block;
  margin-top: 1.2rem;
  background: var(--gold);
  color: var(--ink);
  text-decoration: none;
  padding: 0.7rem 1.4rem;
  border-radius: 2px;
  font-weight: 700;
}
.cta:hover { filter: brightness(1.08); }
.blurb { line-height: 1.5; color: var(--muted); max-width: 40em; margin: 1.5rem auto; }
.board { background: var(--ink-2); border: 1px solid #3a2a48; padding: 1rem 1.2rem; }
.board h2 { font-size: 1.1rem; color: var(--gold); }
.board ol { padding-left: 1.2rem; }
.board li { margin: 0.35rem 0; }
.controls { margin-top: 2rem; color: var(--muted); font-size: 0.95rem; }
.p1 { color: var(--crimson); }
.p2 { color: #8bb6ff; }

.play-body {
  overflow: hidden;
  height: 100dvh;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
#frame {
  position: relative;
  width: min(100vw, calc(100dvh * 512 / 288));
  height: min(100dvh, calc(100vw * 288 / 512));
  margin: 0 auto;
  background: var(--ink);
}
#game { width: 100%; height: 100%; }
.help-touch { display: none; }
.hidden { display: none !important; }

.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: rgba(20, 12, 24, 0.86);
  padding: 1.5rem;
  gap: 0.4rem;
}
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.field input, button, .mode {
  font: inherit;
}
.field input {
  background: #1e1426;
  border: 1px solid #5a4068;
  color: var(--parchment);
  padding: 0.4rem 0.6rem;
  min-width: 12rem;
  max-width: 90vw;
  text-align: center;
  font-size: 16px;
}
.mode { border: 0; color: var(--muted); display: flex; gap: 1rem; }
button {
  margin-top: 0.6rem;
  background: var(--gold);
  color: var(--ink);
  border: 0;
  padding: 0.55rem 1.2rem;
  cursor: pointer;
  font-weight: 700;
}
button:hover { filter: brightness(1.08); }
.help, .back { color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
.error { color: var(--crimson); }
.score-line { color: var(--gold); font-size: 1.1rem; }

.hud {
  position: absolute;
  left: 0; right: 0; top: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.2rem 1rem;
  padding: 6px 10px;
  font-size: 12px;
  font-family: "Segoe UI", sans-serif;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
#hud-floor { grid-column: 1 / -1; color: var(--gold); }
#hud-combo, #hud-status { color: #ffe082; }

.workshop-body { overflow: auto; }
.workshop-bar {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  padding: 0.6rem 1rem;
  background: #1e1426;
  font-size: 0.9rem;
  color: var(--muted);
}
.workshop-bar strong { color: var(--gold); }
.workshop {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: calc(100vh - 40px);
}
.workshop-form {
  padding: 0.8rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  background: var(--ink-2);
  overflow: auto;
}
.workshop-form label { font-size: 0.8rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.2rem; }
.workshop-form input, .workshop-form select, .workshop-form textarea {
  font-family: ui-monospace, Consolas, monospace;
  background: #140c18;
  color: var(--parchment);
  border: 1px solid #5a4068;
  padding: 0.3rem;
}
.workshop-form textarea { min-height: 22rem; line-height: 1.15; font-size: 12px; }
.workshop #game { min-height: 288px; background: var(--ink); }
.legend { font-size: 0.72rem; color: var(--muted); line-height: 1.4; }
.workshop-form .row { display: flex; gap: 0.5rem; }
button.ghost { background: transparent; color: var(--gold); border: 1px solid var(--gold); }
#status { color: var(--gold); font-size: 0.85rem; }

.touch-pad {
  display: none;
  position: relative;
  z-index: 5;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.5rem 0.8rem calc(0.6rem + env(safe-area-inset-bottom));
  background: #100818;
}
.touch-cluster { display: flex; gap: 0.5rem; }
.touch-btn {
  margin: 0;
  min-width: 64px;
  min-height: 64px;
  padding: 0 0.7rem;
  border-radius: 12px;
  background: #3a2a48;
  color: var(--parchment);
  font-size: 1rem;
  font-weight: 700;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.touch-btn.held, .touch-btn:active { background: var(--gold); color: var(--ink); }
.touch-wide { min-width: 88px; }
.touch-pause { min-width: 48px; min-height: 48px; font-size: 0.85rem; opacity: 0.85; }

body.touch-solo {
  display: flex;
  flex-direction: column;
}
body.touch-solo #frame {
  width: 100vw;
  height: auto;
  flex: 1 1 auto;
  aspect-ratio: 512 / 288;
  max-height: calc(100dvh - 132px - env(safe-area-inset-bottom));
}
body.touch-solo #touch-pad:not(.hidden) { display: flex; }
body.touch-solo .help-desktop { display: none; }
body.touch-solo .help-touch { display: block; }
body.touch-solo .panel {
  padding: 1rem 0.8rem;
  overflow: auto;
}
body.touch-solo .hero h1, body.touch-solo h1 { font-size: 2rem; }

@media (max-width: 720px) {
  .hero h1 { font-size: 2.1rem; }
  .wrap { padding: 28px 16px 48px; }
  .workshop { grid-template-columns: 1fr; }
  .workshop-form textarea { min-height: 12rem; }
}

@media (pointer: coarse) and (orientation: landscape) {
  body.touch-solo { flex-direction: row; }
  body.touch-solo #frame {
    flex: 1 1 auto;
    max-height: 100dvh;
    height: 100dvh;
    width: auto;
    aspect-ratio: 512 / 288;
  }
  body.touch-solo #touch-pad:not(.hidden) {
    flex-direction: column;
    justify-content: center;
    width: 150px;
    padding: 0.4rem calc(0.5rem + env(safe-area-inset-right)) 0.4rem 0.4rem;
  }
  body.touch-solo .touch-cluster { flex-direction: column; }
}
