* { box-sizing: border-box; }

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

body {
  background: radial-gradient(ellipse at 50% 0%, #2a3442 0%, #1b222b 60%, #141a21 100%) #1b222b;
  color: #9aa8b5;
  font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.phone {
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.top {
  flex: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbtn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  font: 700 13px/1 system-ui, sans-serif;
  letter-spacing: .05em;
  color: #131c0c;
  background: #8fae4a;
  box-shadow: 0 2px 0 #0e1318;
  cursor: pointer;
}
.topbtn:active { transform: translateY(1px); box-shadow: 0 1px 0 #0e1318; }

.brand {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .45em;
  color: #cfd8e0;
  text-shadow: 0 1px 0 #000;
}
.brand span {
  color: #7c9b3c;
  letter-spacing: .2em;
}

.screen {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lcd {
  display: block;
  touch-action: none;
  border-radius: 8px;
  box-shadow:
    0 0 0 6px #0d1116,
    0 0 0 8px #3a4655,
    0 10px 24px rgba(0, 0, 0, .55);
}

/* D-pad */
.pad {
  --k: clamp(58px, min(19vw, 11vh), 84px);
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, var(--k));
  grid-template-rows: repeat(3, var(--k));
  gap: 8px;
  touch-action: none;
}

.k {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 18px;
  background: linear-gradient(#405063, #2b3644);
  box-shadow: 0 4px 0 #0e1318, inset 0 1px 0 rgba(255, 255, 255, .14);
  color: #dde6ee;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
  outline: none;
  transition: transform .05s, box-shadow .05s;
}
.k.on {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0e1318, inset 0 1px 0 rgba(255, 255, 255, .08);
  background: linear-gradient(#4c5e74, #34414f);
}
.k i {
  width: 36%;
  height: 36%;
  background: currentColor;
  clip-path: polygon(50% 10%, 96% 86%, 4% 86%);
}
.up    { grid-area: 1 / 2; }
.left  { grid-area: 2 / 1; }
.ok    { grid-area: 2 / 2; }
.right { grid-area: 2 / 3; }
.down  { grid-area: 3 / 2; }
.left i  { transform: rotate(-90deg); }
.right i { transform: rotate(90deg); }
.down i  { transform: rotate(180deg); }

.ok {
  border-radius: 50%;
  margin: 10%;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .05em;
  color: #131c0c;
  background: linear-gradient(#8fae4a, #6d8b33);
}
.ok.on { background: linear-gradient(#7c9b3c, #5f7a2b); }

.hint {
  display: none;
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: #6f7d8a;
}
@media (hover: hover) and (pointer: fine) {
  .hint { display: block; }
}

/* Phone in landscape: D-pad to the right of the screen */
@media (orientation: landscape) and (max-height: 540px) {
  .phone {
    max-width: none;
    flex-direction: row;
    justify-content: center;
    gap: 24px;
  }
  .brand, .hint { display: none; }
  .top { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: auto; }
  .screen { height: 100%; width: auto; min-width: 0; flex: 1 1 0; }
  .pad { --k: clamp(48px, 24vh, 80px); }
}

/* Name entry / leaderboard dialog, styled as the LCD */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 14, 18, .72);
  touch-action: manipulation;
}
.modal[hidden] { display: none; }
.panel {
  width: min(100%, 380px);
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 16px;
  border-radius: 10px;
  background: #7c9b3c;
  color: #131c0c;
  font: 600 15px/1.35 ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  box-shadow: 0 0 0 6px #0d1116, 0 0 0 8px #3a4655, 0 14px 30px rgba(0, 0, 0, .6);
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 20px;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.panel label { display: flex; justify-content: space-between; gap: 8px; margin: 6px 0; }
.count { opacity: .7; font-variant-numeric: tabular-nums; }
.panel input {
  width: 100%;
  padding: 10px 12px;
  border: 3px solid #131c0c;
  border-radius: 4px;
  background: #8fae4a;
  color: #131c0c;
  font: 700 16px/1.2 ui-monospace, Menlo, Consolas, monospace; /* 16px: no iOS zoom on focus */
  -webkit-user-select: text;
  user-select: text;
  outline: none;
}
.panel input:focus { background: #9dbb57; }
.muted { margin: 0 0 8px; opacity: .75; font-size: 13px; }
.err { min-height: 1.3em; margin: 6px 0; font-size: 13px; color: #5a0d0d; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.btn {
  appearance: none;
  border: 3px solid #131c0c;
  border-radius: 6px;
  padding: 9px 16px;
  font: 800 15px/1 ui-monospace, Menlo, Consolas, monospace;
  background: #131c0c;
  color: #9dbb57;
  cursor: pointer;
}
.btn.ghost { background: transparent; color: #131c0c; }
.btn:disabled { opacity: .5; }
#boardList {
  margin: 0;
  padding: 0;
  list-style: none;
}
#boardList li {
  display: flex;
  gap: 10px;
  padding: 5px 6px;
  border-bottom: 2px dotted rgba(19, 28, 12, .35);
}
#boardList .p { width: 2.2em; text-align: right; flex: none; font-variant-numeric: tabular-nums; }
#boardList .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#boardList .s { flex: none; font-variant-numeric: tabular-nums; }
#boardList li.me { background: rgba(19, 28, 12, .18); border-radius: 4px; }
#boardList li.new { background: #131c0c; color: #9dbb57; }
