@font-face {
  font-family: "Press Start 2P";
  src: url("/fonts/PressStart2P-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #2a140c;
  --cream: #f6e6c8;
  --cream-2: #e8c98a;
  --navy: #6b2a1a;
  --teal: #c45c12;
  --red: #8e1b24;
  --wood: #8b3a1e;
  --amber: #e8a317;
  --green: #2f6b4f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #2a140c;
  color: var(--cream);
  font-family: "Press Start 2P", monospace;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
input, textarea, #mail-link {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  touch-action: manipulation;
}
canvas#view,
#hud,
#room,
#online,
#greeting,
#dpad,
#dpad button,
#btn-a,
#btn-chat,
#btn-menu,
#btn-sound-hud,
#hint-skip {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
canvas#view {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 0;
  background: #c47a3a;
}
.hidden,
label.hidden,
#name-field.hidden,
#code-field.hidden { display: none !important; }

.screen {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  pointer-events: auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.screen button,
.screen a {
  touch-action: manipulation;
  cursor: pointer;
}
.panel {
  pointer-events: auto;
  width: min(520px, 100%);
  background: var(--cream);
  color: var(--ink);
  border: 4px solid var(--ink);
  box-shadow: inset 0 6px 0 #c45c12, inset -4px -4px 0 #e0b56a, inset 4px 4px 0 #fff6e4, 8px 8px 0 #6b2a1a;
  padding: 18px 16px 16px;
}
.eyebrow, .year, .hint, .note {
  color: var(--teal);
  font-size: 8px;
  line-height: 1.7;
}
h1 {
  margin: 8px 0;
  font-size: 22px;
  line-height: 1.35;
  color: var(--red);
}
h2 { margin: 0 0 10px; font-size: 12px; line-height: 1.6; }
p { font-size: 10px; line-height: 1.7; }
.stack { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 8px; line-height: 1.6; }
input, textarea {
  font-size: 16px;
  padding: 10px;
  border: 3px solid var(--ink);
  background: #fffaf0;
  color: var(--ink);
  width: 100%;
}
button.pixel, .tabs button {
  background: var(--teal);
  color: #f4fffb;
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 12px 10px;
  font-size: 10px;
  line-height: 1.4;
  min-height: 44px;
}
button.pixel.alt { background: var(--navy); }
button.pixel.ghost { background: var(--cream-2); color: var(--ink); }
button.pixel:active, .tabs button:active, .screen button:active { box-shadow: none; }
.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; background: var(--cream-2); color: var(--ink); }
.tabs button.on { background: var(--red); color: var(--cream); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; }
.error { color: var(--red); font-size: 8px; line-height: 1.6; min-height: 1em; }
.spark {
  width: 16px;
  height: 16px;
  margin: 0 auto;
  background: #e8a317;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: spark-bob 0.7s ease-in-out infinite;
}
@keyframes spark-bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-7px) scale(1.15); }
}
#greeting {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(440px, calc(100% - 16px));
  background: rgba(246, 230, 200, 0.96);
  color: var(--ink);
  border: 3px solid var(--ink);
  padding: 8px 8px 6px;
  z-index: 6;
  pointer-events: auto;
}
#greeting p { margin: 0 0 4px; font-size: 8px; line-height: 1.6; }
#hint-skip {
  width: 100%;
  min-height: 36px;
  background: var(--teal);
  color: #fff6e4;
  border: 3px solid var(--ink);
  font-size: 8px;
}
.dev-link {
  display: block;
  background: var(--navy);
  color: var(--cream);
  padding: 12px;
  font-size: 8px;
  line-height: 1.7;
  word-break: break-all;
  text-decoration: none;
  border: 3px solid var(--ink);
}

.swatches, .choices { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch, .choice {
  width: 36px;
  height: 36px;
  border: 3px solid var(--ink);
  padding: 0;
  box-shadow: none;
}
.swatch.on, .choice.on { outline: 3px solid var(--red); outline-offset: 1px; }
.choice {
  width: auto;
  min-width: 44px;
  padding: 0 8px;
  background: var(--cream-2);
  color: var(--ink);
  font-size: 8px;
}
.creator-grid { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; }
#preview {
  width: 120px;
  height: 150px;
  image-rendering: pixelated;
  background: #f0d7a8;
  border: 3px solid var(--ink);
}
.creator-fields { max-height: min(62vh, 560px); overflow: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }

#hud { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 2; pointer-events: none; }
#room {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  background: rgba(107, 42, 26, 0.92);
  color: var(--cream);
  border: 3px solid var(--ink);
  padding: 8px;
  font-size: 8px;
  line-height: 1.6;
  pointer-events: none;
  max-width: 70vw;
}
#online {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  right: 10px;
  background: rgba(243, 236, 220, 0.94);
  color: var(--ink);
  border: 3px solid var(--ink);
  padding: 8px;
  font-size: 8px;
  line-height: 1.7;
  pointer-events: auto;
  max-width: 46vw;
  max-height: 30vh;
  overflow: auto;
}
#online { touch-action: pan-y; }
#online strong { color: var(--teal); }

#chat {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(168px + env(safe-area-inset-bottom));
  width: min(420px, calc(100% - 20px));
  background: rgba(243, 236, 220, 0.96);
  color: var(--ink);
  border: 3px solid var(--ink);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  max-height: 34vh;
}
#chat-log { overflow: auto; padding: 8px; font-size: 10px; line-height: 1.7; min-height: 72px; }
#chat-log .me { color: var(--navy); }
#chat-log .event { color: var(--green); }
#chat form { display: flex; gap: 6px; padding: 6px; border-top: 3px solid var(--ink); }
#chat input { flex: 1; }
#chat button { width: 72px; }

#dialog {
  position: absolute;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(640px, calc(100% - 16px));
  max-height: min(72vh, 640px);
  overflow: auto;
  pointer-events: auto;
  z-index: 5;
}
#dialog h2 { color: var(--red); }
#dialog.tv-guide {
  top: calc(8px + env(safe-area-inset-top));
  bottom: calc(12px + env(safe-area-inset-bottom));
  max-height: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #1a120e;
  color: #f6e6c8;
  border: 4px solid #f2c572;
  box-shadow: inset 0 0 0 3px #6b2a1a, 6px 6px 0 #2a140c;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#dialog.tv-guide::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 4px);
}
#dialog.tv-guide h2 { color: #f2c572; margin: 0; }
#dialog.tv-guide p { margin: 0; }
.tv-head { display: flex; flex-direction: column; gap: 6px; position: relative; }
.tv-title { color: #f6e6c8; font-size: 8px; line-height: 1.6; }
.tv-fav, .tv-badge { color: #f2c572; }
.tv-list {
  overflow: auto;
  flex: 1;
  min-height: 0;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  border-top: 3px solid #6b2a1a;
  border-bottom: 3px solid #6b2a1a;
}
.tv-group {
  padding: 8px;
  background: #6b2a1a;
  color: #f2c572;
  font-size: 8px;
  line-height: 1.6;
}
.tv-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px;
  border: 0;
  border-bottom: 2px solid #3a2418;
  background: transparent;
  color: #f6e6c8;
  font-family: inherit;
  font-size: 8px;
  line-height: 1.6;
  text-align: left;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.tv-row.on { background: #3a2418; box-shadow: inset 0 0 0 2px #f2c572; }
.tv-row.crowd { box-shadow: inset 4px 0 0 #e07a3d; }
.tv-row.on.crowd { box-shadow: inset 4px 0 0 #e07a3d, inset 0 0 0 2px #f2c572; }
.tv-main { flex: 1; min-width: 0; }
.tv-meta, .tv-place { color: #e07a3d; }
.tv-match { color: #fff6e4; font-size: 9px; }
.tv-people { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; color: #e8c98a; }
.tv-people canvas { width: 16px; height: 24px; image-rendering: pixelated; background: #2a140c; }
.tv-check {
  flex: none;
  min-width: 72px;
  text-align: center;
  border: 2px solid #e8c98a;
  padding: 6px;
  color: #e8c98a;
}
.tv-check.on { background: #2f6b4f; color: #f6e6c8; border-color: #f2c572; }
.tv-foot { color: #e8c98a; font-size: 8px; line-height: 1.6; }
@media (max-width: 1024px), (pointer: coarse) {
  #dialog.tv-guide { bottom: calc(168px + env(safe-area-inset-bottom)); }
}
#dialog .items { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
#dialog .item {
  background: #fffaf0;
  border: 3px solid var(--ink);
  padding: 8px;
  font-size: 10px;
  line-height: 1.6;
}
.note-box { background: #efe2a8; border: 3px solid var(--ink); padding: 8px; font-size: 8px; line-height: 1.6; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.magnet {
  background: #fff;
  border: 4px solid #f7f4ee;
  box-shadow: 2px 3px 0 var(--ink);
  padding: 6px 6px 8px;
  transform: rotate(-1.5deg);
}
.magnet:nth-child(2n) { transform: rotate(1.5deg); }
.magnet img { width: 100%; height: 88px; object-fit: cover; image-rendering: auto; background: #ddd; }
.magnet p { margin: 6px 0 0; }
.lightbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(10, 12, 16, 0.82);
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: auto;
}
.lightbox img { max-width: min(92vw, 800px); max-height: 70vh; border: 8px solid white; }
.lightbox p { color: white; font-size: 8px; line-height: 1.7; text-align: center; }

.dpad {
  position: absolute;
  left: calc(10px + env(safe-area-inset-left));
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: 148px;
  height: 148px;
  pointer-events: auto;
  touch-action: none;
}
.dpad button {
  position: absolute;
  width: 48px;
  height: 48px;
  background: rgba(243, 236, 220, 0.94);
  color: var(--ink);
  border: 3px solid var(--ink);
  font-size: 14px;
  padding: 0;
}
.dpad button::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  margin: 16px auto 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 12px solid var(--ink);
  pointer-events: none;
}
.dpad .d::before { transform: rotate(180deg); margin-top: 14px; }
.dpad .l::before { transform: rotate(-90deg); margin-top: 16px; }
.dpad .r::before { transform: rotate(90deg); margin-top: 16px; }
.dpad .u { left: 50px; top: 0; }
.dpad .l { left: 0; top: 50px; }
.dpad .r { left: 100px; top: 50px; }
.dpad .d { left: 50px; top: 100px; }
#btn-a {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(36px + env(safe-area-inset-bottom));
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  border: 4px solid var(--ink);
  box-shadow: 3px 3px 0 #1a120e;
  font-size: 18px;
  pointer-events: auto;
  touch-action: manipulation;
}
#btn-a::before {
  content: "A";
  pointer-events: none;
}
body.rowing #btn-a { display: block; }
body.rowing #dpad,
body.rowing #room { display: none !important; }
#rowing-close {
  position: fixed;
  z-index: 6;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(36px + env(safe-area-inset-bottom));
  min-width: 88px;
  min-height: 44px;
  padding: 8px 10px;
  font-size: 10px;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--ink);
  pointer-events: auto;
  touch-action: manipulation;
}
#rowing-result { z-index: 7; }
#rowing-list { display: flex; flex-direction: column; gap: 6px; max-height: 42vh; overflow: auto; }
.rowing-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #fffaf0;
  border: 3px solid var(--ink);
  padding: 4px;
  font-size: 8px;
  line-height: 1.5;
}
.rowing-row.mine { background: #f2c572; }
.rowing-row canvas { width: 32px; height: 48px; image-rendering: pixelated; background: #e7d3b0; flex: none; }
#btn-chat, #btn-menu, #btn-sound-hud {
  position: absolute;
  pointer-events: auto;
  min-height: 36px;
  padding: 8px;
  font-size: 8px;
  background: var(--navy);
  color: var(--cream);
  border: 3px solid var(--ink);
}
#btn-sound {
  width: 100%;
}
#btn-sound-hud {
  left: 10px;
  top: calc(48px + env(safe-area-inset-top));
  min-width: 72px;
  min-height: 40px;
  font-size: 10px;
  background: rgba(246, 230, 200, 0.94);
  color: var(--ink);
}
#btn-sound-hud[aria-pressed="true"] { background: #6b2a1a; color: var(--cream); }
#btn-chat { right: calc(16px + env(safe-area-inset-right)); bottom: calc(120px + env(safe-area-inset-bottom)); }
#btn-menu { right: calc(16px + env(safe-area-inset-right)); top: calc(10px + env(safe-area-inset-top)); }
.touch { display: none; }
@media (max-width: 1024px), (pointer: coarse) {
  .touch { display: block; }
  #btn-chat, #btn-menu { display: block; }
  #dialog { bottom: calc(168px + env(safe-area-inset-bottom)); }
  #greeting { bottom: calc(168px + env(safe-area-inset-bottom)); }
}
@media (min-width: 1025px) and (pointer: fine) {
  #chat { bottom: 16px; left: auto; right: 16px; }
  #btn-chat, #btn-menu { display: block; }
  #btn-chat { bottom: 16px; right: 16px; }
  #dialog { bottom: 16px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .dpad { transform: scale(0.72); transform-origin: bottom left; }
  #btn-a { width: 58px; height: 58px; }
  h1 { font-size: 16px; }
  .creator-grid { grid-template-columns: 90px 1fr; }
  .creator-fields { max-height: 58vh; }
  #chat { max-height: 28vh; bottom: 8px; }
}
@media (max-width: 420px) {
  h1 { font-size: 16px; }
  .creator-grid { grid-template-columns: 84px 1fr; }
  #preview { width: 84px; height: 110px; }
}
