:root {
  --cyan: rgb(0 242 199);
  --yellow: rgb(255 224 26);
  --magenta: rgb(255 20 143);
  --panel: rgb(0 0 0 / 0.7);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --key: 44px;
  --key-gap: 6px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--mono), system-ui, sans-serif;
  color: #fff;
  background: linear-gradient(135deg, #141209 0%, #3d3324 50%, #1c1913 100%) fixed;
  padding-inline: 16px;
  padding-block: 16px;
  overflow-x: hidden;
}

/* Retro backdrop: scanlines, subtle streaks, and the tilted watermark. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background:
    repeating-linear-gradient(to bottom, rgb(0 0 0 / 0.055) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(115deg, rgb(255 255 255 / 0.02) 0 1px, transparent 1px 37px);
}

.backdrop-mark {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-30%, -50%) rotate(-27deg);
  font-family: var(--mono);
  font-size: clamp(90px, 22vw, 170px);
  font-weight: 900;
  color: rgb(0 242 199 / 0.1);
  white-space: nowrap;
}

.backdrop-version {
  position: absolute;
  right: 28px;
  bottom: 28px;
  font: italic 900 18px Georgia, "Times New Roman", serif;
  color: rgb(0 0 0 / 0.38);
}

#app {
  outline: none;
  max-width: 1100px;
  margin-inline: auto;
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

:where(a:any-link, button, input, select):focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

.retro-panel {
  padding: 14px;
  background: var(--panel);
  border: 2px solid;
  border-image: linear-gradient(135deg, rgb(255 255 255 / 0.65), #000, rgb(255 255 255 / 0.22)) 1;
  box-shadow: 5px 6px 0 rgb(0 0 0 / 0.85);
}

.retro-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 9px 12px;
  font-family: var(--mono);
  font-weight: 700;
  color: #fff;
  background: rgb(0 0 0 / 0.84);
  border: 1.5px solid rgb(0 242 199 / 0.8);
  box-shadow: 3px 3px 0 rgb(0 0 0 / 0.85);
}

.retro-button.accent-yellow {
  border-color: rgb(255 224 26 / 0.8);
}

.retro-button:active:not(:disabled) {
  color: #000;
  background: var(--cyan);
  border-color: #fff;
}

.retro-button.accent-yellow:active:not(:disabled) {
  background: var(--yellow);
}

.retro-button:disabled {
  opacity: 0.45;
}

.retro-button.block {
  width: 100%;
}

.wordmark {
  margin: 0;
  font-family: var(--mono);
  font-weight: 900;
  font-size: 68px;
  letter-spacing: -2px;
  line-height: 1.05;
  text-shadow: 0 0 3px var(--cyan), 0 0 6px var(--cyan);
}

.wordmark.compact {
  font-size: 37px;
  letter-spacing: -1px;
}

.glow-cyan {
  color: var(--cyan);
  text-shadow: 0 0 4px var(--cyan);
}

.muted {
  color: rgb(255 255 255 / 0.62);
}

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

/* Player entry */
.entry {
  max-width: 620px;
  margin: 40px auto;
  text-align: center;
}

.entry .retro-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 24px;
}

.entry form {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.entry label {
  align-self: flex-start;
  font-weight: 700;
  color: var(--yellow);
}

.entry input {
  width: 100%;
  padding: 10px;
  font: 22px var(--mono);
  color: #fff;
  background: #000;
  border: 1.5px solid var(--cyan);
}

/* Home */
.home {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.home-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.home-header .actions {
  display: flex;
  gap: 8px;
}

.player-line {
  margin: 2px 0 0;
  color: var(--cyan);
}

.mode-section h2 {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 700;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr));
  gap: 8px;
}

.mode-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 12px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  text-align: left;
  color: #fff;
  background: linear-gradient(135deg, #3b3b3b, #121212, #2e2e2e);
  border: 1.5px solid var(--accent, #888);
  box-shadow: 3px 3px 0 #000;
}

.mode-button:disabled {
  color: rgb(255 255 255 / 0.55);
  border-color: #777;
  opacity: 1;
}

.mode-button.selected {
  outline: 4px solid var(--yellow);
  outline-offset: -2px;
}

.mode-button .icon {
  width: 20px;
  flex: none;
  text-align: center;
}

/* Game */
.game {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.game-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
}

.game-header .best {
  margin-left: auto;
}

/* Board and status share one centered column, so the keyboard sits under their middle. */
.game-main {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 22px;
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.board-frame {
  flex: 0 1 404px;
  width: min(100%, 404px);
  padding: 10px;
  background: rgb(0 0 0 / 0.86);
  border: 2px solid rgb(255 255 255 / 0.65);
  box-shadow: 5px 6px 0 #000;
}

.board {
  display: block;
  width: 100%;
  aspect-ratio: 8 / 11;
  image-rendering: pixelated;
  background: #000;
}

.status-panel {
  flex: none;
  width: 190px;
  min-width: 0;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.status-panel .metric-label {
  margin: 0;
  font-size: 13px;
}

.status-panel .metric-value {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.status-panel .hint {
  margin-top: auto;
}

/* Screen keyboard */
.screen-keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--key-gap);
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
  padding: 12px;
  background: rgb(0 0 0 / 0.86);
  border: 1.5px solid rgb(255 255 255 / 0.3);
  user-select: none;
  -webkit-user-select: none;
}

.screen-keyboard .row {
  display: flex;
  gap: var(--key-gap);
}

.key {
  width: calc(var(--key) * var(--w, 1));
  height: var(--key);
  padding: 0;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(9px, calc(var(--key) * 0.34), 15px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  color: #fff;
  background: rgb(var(--finger) / 0.68);
  border: 1.5px solid rgb(0 0 0 / 0.7);
  box-shadow: 2px 2px 0 #000;
  touch-action: manipulation;
}

.key:active {
  filter: brightness(1.18);
  transform: translateY(2px);
}

.key.target {
  color: #000;
  background: var(--yellow);
  border-color: #fff;
  box-shadow: 2px 2px 5px var(--yellow);
}

.key.page-toggle {
  --w: 1.909;
  background: rgb(128 128 128 / 0.5);
  border-color: rgb(255 255 255 / 0.5);
}

.key.page-toggle.target {
  background: var(--yellow);
  color: #000;
}

.screen-keyboard:disabled,
.screen-keyboard[aria-disabled="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* End overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.65);
}

.result-card {
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 24px;
  background: rgb(0 0 0 / 0.94);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgb(0 242 199 / 0.5);
  font-family: var(--mono);
}

.result-card h2 {
  margin: 0;
  font-size: 32px;
  color: var(--cyan);
}

.result-card h2.game-over {
  font-size: 52px;
  font-weight: 900;
  color: #fff;
}

.result-card .record {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--yellow);
}

.result-card dl {
  width: 100%;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 16px;
}

.result-card dt {
  color: rgb(255 255 255 / 0.7);
}

.result-card dd {
  margin: 0;
  text-align: right;
}

.result-card .space-hint {
  margin: 0;
  color: var(--yellow);
}

/* Dialogs */
.retro-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  color: #fff;
  background: #121212;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgb(0 242 199 / 0.4);
}

.retro-dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgb(255 255 255 / 0.2);
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dialog-body section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: rgb(255 255 255 / 0.7);
}

.dialog-body dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 16px;
}

.dialog-body dd {
  margin: 0;
  text-align: right;
  color: var(--cyan);
}

.dialog-body label.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.dialog-body select {
  font: inherit;
  padding: 6px 8px;
  color: #fff;
  background: #000;
  border: 1.5px solid var(--cyan);
}

.dialog-body a {
  color: var(--cyan);
}

.link-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.noscript {
  padding: 16px;
  text-align: center;
}

@media (max-width: 640px) {
  .wordmark {
    font-size: 48px;
  }

  .status-panel {
    width: 100%;
    min-height: 0;
  }

  .status-panel .hint {
    margin-top: 0;
  }
}

/* Online duel */
.duel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.duel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.duel-header h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
}

.duel-header .room-tag {
  margin-left: auto;
}

.duel-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 16px;
}

.duel-forms form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.duel-forms h2 {
  margin: 0;
  font-size: 18px;
}

.duel-forms input {
  width: 100%;
  padding: 10px;
  font: 22px var(--mono);
  letter-spacing: 0.2em;
  color: #fff;
  background: #000;
  border: 1.5px solid var(--cyan);
}

.room-code {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0;
}

.room-code strong {
  font-size: 44px;
  letter-spacing: 0.15em;
  color: var(--yellow);
  text-shadow: 0 0 6px rgb(255 224 26 / 0.6);
}

.room-players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: 8px 16px;
  margin: 0;
}

.room-players dt {
  font-size: 13px;
  color: rgb(255 255 255 / 0.62);
}

.room-players dd {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--cyan);
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 6px;
  font-size: 12px;
  font-style: normal;
  color: #000;
  background: var(--yellow);
}

.badge.away {
  color: #fff;
  background: var(--magenta);
}

.room-request {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1.5px solid var(--yellow);
}

.room-request p {
  margin: 0;
  flex: 1 1 200px;
}

.room-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rules {
  margin: 0;
  padding-left: 1.2em;
  font-size: 13px;
  color: rgb(255 255 255 / 0.7);
}

.rules li + li {
  margin-top: 4px;
}

.attack-gauge {
  display: flex;
  gap: 4px;
  margin: 4px 0;
}

.attack-gauge span {
  width: 24px;
  height: 10px;
  background: rgb(255 255 255 / 0.15);
  border: 1px solid rgb(255 255 255 / 0.4);
}

.attack-gauge span.filled {
  background: var(--yellow);
}

.attack-button:not(:disabled) {
  color: #000;
  background: var(--yellow);
  border-color: #fff;
  box-shadow: 0 0 10px var(--yellow);
}

.duel-notice {
  min-height: 1.4em;
  margin: 0;
  color: var(--yellow);
}

.countdown-number {
  margin: 0;
  font-size: 120px;
  font-weight: 900;
  line-height: 1;
  color: var(--yellow);
  text-shadow: 0 0 20px var(--yellow);
}

.result-card .versus {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.result-card .versus > div {
  padding: 10px;
  border: 1px solid rgb(255 255 255 / 0.3);
  text-align: center;
}

.result-card .versus h3 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--cyan);
  overflow-wrap: anywhere;
}

.result-card .versus p {
  margin: 2px 0;
  font-size: 14px;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-list li {
  padding: 8px 0;
  border-bottom: 1px solid rgb(255 255 255 / 0.15);
}

.history-list .outcome {
  font-weight: 700;
  color: var(--yellow);
}
