@font-face {
  font-family: 'PressStart';
  src: url('../assets/fonts/PressStart2P-Regular.ttf') format('truetype');
  font-display: block;
}

:root {
  --ink: #2a160a;
  --cream: #d8c890;
  --cream-hi: #f8f0c0;
  --cream-lo: #a89860;
  --key: #e8e0c8;
  --key-lo: #b8b098;
  --orange: #f8a830;
  --orange-lo: #e08820;
  --red: #c01818;
  --wood: repeating-linear-gradient(0deg, #7a4a24 0 6px, #6e4220 6px 10px, #835028 10px 14px);
  --app-w: min(100vw, 520px);
  --stage-h: min(calc(var(--app-w) * 4 / 3), calc(100dvh - 220px));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #1c1008;
  overscroll-behavior: none;
  overflow: hidden;
}

body, button, input {
  font-family: 'PressStart', monospace;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: relative;
  width: var(--app-w);
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--wood);
  overflow: hidden;
  image-rendering: pixelated;
}

/* ---------- HUD ---------- */
#hud {
  flex: 1 1 0;
  min-height: 92px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border-bottom: 6px solid var(--ink);
}

.plate {
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: inset -3px -3px 0 var(--cream-lo), inset 3px 3px 0 var(--cream-hi);
  padding: 7px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

#lives { display: flex; gap: 4px; }
#lives svg.lost { opacity: .35; }
#lives.hit { animation: pop .4s steps(4); }

.labels {
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  min-height: 8px;
  color: var(--cream-hi);
  text-shadow: 1px 1px 0 #000;
}
#label-right { color: var(--orange); }

.bar-row { display: flex; align-items: center; gap: 8px; }
#bar {
  flex: 1;
  height: 16px;
  background: var(--ink);
  border: 3px solid var(--cream);
  position: relative;
}
#bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--orange) 0 8px, var(--orange-lo) 8px 10px);
}
#bar.danger #bar-fill { background: repeating-linear-gradient(90deg, #f84830 0 8px, #c02010 8px 10px); }
#quota { font-size: 8px; color: var(--cream-hi); text-shadow: 1px 1px 0 #000; min-width: 40px; text-align: right; }
#quota.done { color: #78f878; }

/* ---------- Stage (3:4 video) ---------- */
#stage {
  flex: none;
  position: relative;
  height: var(--stage-h);
  width: calc(var(--stage-h) * 3 / 4);
  margin: 0 auto;
  background: #000;
  overflow: hidden;
}
#stage video, #stage #idle {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  visibility: hidden;
  pointer-events: none;
}
#stage video.on, #stage #idle.on { visibility: visible; }

#banner {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 8%;
  padding: 10px 8px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: #fff;
  background: rgba(42, 22, 10, .82);
  border: 3px solid var(--cream);
  text-shadow: 2px 2px 0 #000;
  display: none;
}
#banner.on { display: block; animation: pop .25s steps(3); }
#banner.alert { color: #ffd040; border-color: #f84830; }

/* ---------- Controls ---------- */
#controls {
  flex: 1.5 1 0;
  min-height: 110px;
  display: flex;
  gap: 12px;
  padding: 12px 12px calc(env(safe-area-inset-bottom) + 16px);
  border-top: 6px solid var(--ink);
}

.key {
  flex: 1;
  background: var(--key);
  border: 3px solid var(--ink);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 14px;
  box-shadow: inset -5px -8px 0 var(--key-lo), inset 4px 4px 0 #fff, 0 6px 0 var(--ink);
  cursor: pointer;
  outline: none;
}
.key.down, .key:active {
  transform: translateY(5px);
  box-shadow: inset -5px -4px 0 var(--key-lo), inset 4px 4px 0 #fff, 0 1px 0 var(--ink);
}
.key.wide { flex: none; width: 70%; padding: 16px 0; font-size: 14px; }
#controls.locked .key { filter: brightness(.8); }

/* ---------- Full-screen overlays ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: calc(env(safe-area-inset-top) + 20px) 18px calc(env(safe-area-inset-bottom) + 20px);
  text-align: center;
  color: var(--cream-hi);
  text-shadow: 2px 2px 0 #000;
  background: rgba(28, 16, 8, .92);
}
.screen.on { display: flex; }

#screen-title {
  background:
    linear-gradient(rgba(28, 16, 8, .55), rgba(28, 16, 8, .85)),
    url('../assets/video/office/idle.jpg') center / cover;
}
#screen-title h1 {
  font-size: 40px;
  line-height: 1.3;
  font-weight: normal;
  color: var(--orange);
  text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--cream-hi);
}
#title-player { font-size: 10px; color: var(--cream); }
.blink { font-size: 14px; animation: blink 1s steps(1) infinite; }

h2 { font-size: 15px; line-height: 1.6; font-weight: normal; color: var(--orange); }

#nick-input {
  width: 85%;
  padding: 14px 8px;
  font-size: 16px; /* >= 16px stops iOS zooming into the field */
  text-align: center;
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: inset 3px 3px 0 var(--cream-lo);
  user-select: text;
  -webkit-user-select: text;
}
#nick-msg { font-size: 8px; line-height: 1.8; color: var(--cream); min-height: 16px; }
#nick-msg.error { color: #ff8060; }

#card { background: #120a04; }
#card-text {
  font-size: 22px;
  line-height: 1.7;
  color: var(--cream-hi);
  padding: 22px 14px;
  border: 4px solid var(--orange);
  box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 4px #000;
  background: var(--ink);
}
#card.on #card-text { animation: pop .35s steps(4); }

#end-title { font-size: 24px; }
#end-score { font-size: 13px; }
#end-rank { font-size: 11px; color: var(--orange); }
#end-board {
  list-style: none;
  width: 100%;
  background: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: inset -3px -3px 0 var(--cream-lo), inset 3px 3px 0 var(--cream-hi);
  padding: 8px 6px;
  color: var(--ink);
  text-shadow: none;
  font-size: 9px;
}
#end-board:empty { display: none; }
#end-board li { display: flex; gap: 8px; padding: 5px 4px; }
#end-board li .r { width: 32px; text-align: left; }
#end-board li .n { flex: 1; text-align: left; }
#end-board li.me { background: var(--orange); }
#end-board li.gap { justify-content: center; }

/* ---------- Effects ---------- */
#flash {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #f01818;
  opacity: 0;
  pointer-events: none;
}
#flash.on { animation: flash .35s steps(3); }
#app.shake { animation: shake .3s steps(6); }

@keyframes blink { 50% { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(6px, -2px); }
  60% { transform: translate(-4px, 0); }
  80% { transform: translate(4px, 2px); }
}

@media (max-height: 640px) {
  #hud { min-height: 84px; gap: 5px; }
  #controls { min-height: 96px; }
  .key { font-size: 12px; gap: 6px; }
}

.key[hidden] { display: none; }
#nick-skip { font-size: 11px; }
