* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #07070d;
  color: #9aa0c0;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Courier New", Courier, monospace;
  -webkit-tap-highlight-color: transparent;
}

#cabinet {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 8px;
}

#screen {
  position: relative;
  width: min(calc(100vw - 16px), calc((100vh - 130px) * 4 / 3), 1100px);
  width: min(calc(100vw - 16px), calc((100dvh - 130px) * 4 / 3), 1100px);
  aspect-ratio: 4 / 3;
  background: #000;
  border: 6px solid #1c1c2b;
  border-radius: 14px;
  box-shadow: 0 0 0 2px #35355a, 0 0 40px rgba(60, 90, 255, 0.25);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#screen::after {
  /* very light scanlines for the CRT feel */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,0.12) 3px);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  max-width: 1100px;
}

#who {
  color: #40e0ff;
  font-size: 13px;
  font-weight: bold;
  margin-right: 4px;
}

button {
  font: inherit;
  font-weight: bold;
  letter-spacing: 1px;
  color: #ffd400;
  background: #14142a;
  border: 2px solid #35355a;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
button:hover { background: #1d1d3d; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:focus-visible, input:focus-visible { outline: 2px solid #40e0ff; outline-offset: 2px; }
button.ghost { color: #9aa0c0; }

footer {
  font-size: 13px;
  color: #7c82a8;
  letter-spacing: 1px;
}

/* ---- touch controls (overlay on the screen) ---- */
#touch {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
body.touch #touch { display: block; }
/* rotated mode: the touch layer stays a plain full-screen layer (no transform on it, which iOS Safari
   handles badly for fixed layers); game.js places each button and the CSS below turns the button itself */
body.rot #touch button { transform: translate(-50%, -50%) rotate(90deg); }

#touch .grp { display: flex; gap: 6px; }

#touch button {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  width: clamp(46px, 14vw, 76px);
  height: clamp(46px, 14vw, 76px);
  padding: 0;
  font-size: clamp(10px, 2.8vw, 14px);
  color: #fff;
  background: rgba(20, 20, 50, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 12px;
}
#touch button.on { background: rgba(255, 212, 0, 0.55); color: #000; }

/* ---- dialogs ---- */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 10, 0.88);
  z-index: 10;
  padding: 12px;
}
.modal.open { display: flex; }

.card {
  width: min(440px, 100%);
  max-height: 94vh;
  overflow-y: auto;
  background: #0d0d1e;
  border: 2px solid #35355a;
  border-radius: 10px;
  box-shadow: 0 0 30px rgba(60, 90, 255, 0.25);
  padding: 18px;
  color: #c8ccec;
}
.card h1, .card h2 {
  margin: 0 0 8px;
  color: #ffd400;
  letter-spacing: 3px;
  text-align: center;
}
.card h1 { font-size: 26px; }
.card h2 { font-size: 20px; }
.card .sub { margin: 0 0 12px; font-size: 13px; line-height: 1.45; }
.card .fine { margin: 10px 0 0; font-size: 12px; color: #7c82a8; }
.card label { display: block; margin: 10px 0 4px; font-size: 13px; color: #9aa0c0; }
.card input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  letter-spacing: 2px;
  color: #fff;
  background: #07071a;
  border: 2px solid #35355a;
  border-radius: 6px;
  padding: 8px 10px;
}
.card .btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.card p[role="alert"], .card p[role="status"] { min-height: 1.3em; margin: 10px 0 0; font-size: 13px; text-align: center; }
.err { color: #ff6a6a; }
.ok { color: #5dff8a; }

.rows { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.rows .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #11112a;
}
.rows .row.me { outline: 1px solid #40e0ff; }
.rows .row .keys { display: flex; gap: 6px; }
.rows .row .tag { color: #40e0ff; font-size: 12px; }
.keybtn { min-width: 84px; font-size: 13px; padding: 5px 8px; color: #fff; }
.keybtn.cap { background: #3a2a00; border-color: #ffd400; color: #ffd400; }

.big {
  text-align: center;
  font-size: 44px;
  font-weight: bold;
  letter-spacing: 12px;
  padding-left: 12px;
  color: #ffd400;
  margin: 4px 0 8px;
}

#pingBar { font-size: 12px; font-weight: bold; color: #9aa0c0; }
.ping.g { color: #5dff8a; }
.ping.y { color: #ffd400; }
.ping.r { color: #ff6a6a; }
.ping.n { color: #9aa0c0; }
.rows .row .ping { font-size: 13px; font-weight: bold; }

.card .menu { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.card .menu button { width: 100%; font-size: 16px; padding: 12px; letter-spacing: 3px; }
.rows .row .st { display: flex; align-items: center; gap: 10px; }
.rdy { font-size: 12px; font-weight: bold; color: #ff6a6a; }
.rdy.on { color: #5dff8a; }
#btnRoomReady.on { background: #0e3a1a; border-color: #5dff8a; color: #5dff8a; }

.cfgv { min-width: 34px; text-align: center; color: #fff; font-weight: bold; align-self: center; }
.keybtn.mini { min-width: 38px; }

#btnRotate { display: none; }
body.touch #btnRotate { display: inline-block; }
body.rot #cabinet {
  position: fixed; top: 0; left: 0;
  width: 100vh; width: 100dvh;
  height: 100vw; height: 100dvw;
  min-height: 0;
  transform-origin: top left;
  transform: translateX(100vw) rotate(90deg);
}
body.rot #screen {
  width: min(calc(100vh - 16px), calc((100vw - 100px) * 4 / 3), 1100px);
  width: min(calc(100dvh - 16px), calc((100dvw - 100px) * 4 / 3), 1100px);
}

/* no text selection, no long-press callout, no double-tap zoom (phones) */
html, body, body * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
html, body { touch-action: manipulation; }
input, textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* ---- vertical menu panel ---- */
#barToggle {
  position: fixed; top: 8px; right: 8px; z-index: 8;
  padding: 8px 12px; font-size: 18px; line-height: 1;
}
#bar {
  position: fixed; top: 52px; right: 8px; z-index: 9;
  display: none;
  flex-direction: column; flex-wrap: nowrap;
  align-items: stretch; justify-content: flex-start;
  gap: 6px;
  min-width: 190px; max-width: calc(100vw - 16px);
  max-height: calc(100vh - 64px); max-height: calc(100dvh - 64px);
  overflow-y: auto;
  background: #0d0d1e;
  border: 2px solid #35355a; border-radius: 10px;
  padding: 10px;
  box-shadow: 0 0 30px rgba(60, 90, 255, 0.25);
}
body.barOpen #bar { display: flex; }
#bar button { width: 100%; text-align: left; }
#who, #pingBar { text-align: left; margin: 0; }
#who:empty, #pingBar:empty { display: none; }
#screen {
  width: min(calc(100vw - 16px), calc((100vh - 50px) * 4 / 3), 1100px);
  width: min(calc(100vw - 16px), calc((100dvh - 50px) * 4 / 3), 1100px);
}
#btnLayout { display: none; }
body.touch #btnLayout { display: block; }
body.layout #barToggle, body.layout #bar { display: none !important; }

/* ---- movable / resizable touch buttons ---- */
#touch .grp { display: contents; }
#touch button {
  position: absolute;
  transform: translate(-50%, -50%);
  height: auto; aspect-ratio: 1 / 1;
  min-width: 40px;
  font-size: 12px;
}
body.layout #touch button { outline: 2px dashed #40e0ff; outline-offset: 2px; background: rgba(20, 20, 50, 0.75); }
body.layout #touch button.sel { outline-color: #ffd400; }

#layoutPanel {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 64px); left: 50%; transform: translateX(-50%);
  z-index: 20;
  width: min(420px, calc(100vw - 16px));
  background: #0d0d1e; border: 2px solid #35355a; border-radius: 10px;
  padding: 10px; color: #c8ccec; font-size: 13px; text-align: center;
  box-shadow: 0 0 30px rgba(60, 90, 255, 0.35);
}
#layoutPanel p { margin: 0 0 8px; }
#layoutPanel label { display: flex; align-items: center; gap: 10px; }
#layoutPanel input[type="range"] { flex: 1; }
#layoutPanel .btns { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

/* ---- top bar with hamburger (inside the cabinet, so it rotates with the game) ---- */
#cabinet { position: relative; }
#topbar {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: min(calc(100vw - 16px), calc((100vh - 100px) * 4 / 3), 1100px);
  width: min(calc(100vw - 16px), calc((100dvh - 100px) * 4 / 3), 1100px);
  min-height: 36px;
}
body.rot #topbar {
  width: min(calc(100vh - 16px), calc((100vw - 100px) * 4 / 3), 1100px);
  width: min(calc(100dvh - 16px), calc((100dvw - 100px) * 4 / 3), 1100px);
}
#topbar .tl { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#btnBarToggle { position: static; flex: none; padding: 8px 12px; font-size: 18px; line-height: 1; }
#bar {
  position: absolute; top: calc(100% + 4px); right: 0; left: auto; z-index: 9;
  max-height: calc(100vh - 110px); max-height: calc(100dvh - 110px);
}
body.rot #bar { max-height: calc(100vw - 110px); max-height: calc(100dvw - 110px); }
#screen {
  width: min(calc(100vw - 16px), calc((100vh - 100px) * 4 / 3), 1100px);
  width: min(calc(100vw - 16px), calc((100dvh - 100px) * 4 / 3), 1100px);
}
body.layout #btnBarToggle { display: none; }
/* dialogs rotate together with the game */
body.rot .modal {
  inset: auto; top: 0; left: 0;
  width: 100vh; width: 100dvh;
  height: 100vw; height: 100dvw;
  transform-origin: top left;
  transform: translateX(100vw) rotate(90deg);
}

#touch button[data-k="horn"] { border-color: rgba(255, 170, 0, 0.8); }

#toast {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 64px); left: 50%; transform: translateX(-50%);
  z-index: 30; max-width: calc(100vw - 24px);
  background: #0d0d1e; border: 2px solid #35355a; border-radius: 8px;
  padding: 8px 12px; color: #fff; font-size: 13px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

/* ---- quick quotes ---- */
#touch button.qb {
  min-width: 36px;
  padding: 0 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: system-ui, "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  border-color: rgba(64, 224, 255, 0.8);
}
#touch button.qb.on { background: rgba(64, 224, 255, 0.6); }
#touch button.qb.cool { opacity: 0.45; }
.qrow { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 6px; background: #11112a; }
.qrow .qn { color: #ffd400; font-weight: bold; width: 18px; text-align: center; }
.qrow input { font-size: 16px; letter-spacing: 0; padding: 6px 8px; font-family: system-ui, "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.emojis { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: 10px; }
.emojis button { padding: 4px 6px; font-size: 20px; line-height: 1; min-width: 38px; background: #11112a; }

/* rotated mode: the dialog frame is only as tall as the screen is wide, so the card must fit that height */
body.rot .card { max-height: 94vw; max-height: 94dvw; }
body.rot #quotes .card { padding: 10px 14px; }
body.rot #quotes .card h2 { margin-bottom: 4px; font-size: 16px; }
body.rot .qrow { padding: 2px 8px; }
body.rot .qrow input { padding: 3px 8px; }
body.rot .emojis { margin-top: 6px; }
body.rot .emojis button { padding: 2px 4px; font-size: 16px; min-width: 30px; }
body.rot #quotes .card .btns { margin-top: 8px; }
@media (max-height: 460px) {
  #quotes .card { padding: 10px 14px; }
  #quotes .card h2 { margin-bottom: 4px; font-size: 16px; }
  .qrow { padding: 2px 8px; }
  .qrow input { padding: 3px 8px; }
  .emojis { margin-top: 6px; }
  .emojis button { padding: 2px 4px; font-size: 16px; min-width: 30px; }
  #quotes .card .btns { margin-top: 8px; }
}

/* ---- always-available rotate button (touch devices) ---- */
#rotFab {
  display: none;
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 6px); left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: 40px; height: 40px; padding: 0;
  font-size: 24px; line-height: 1;
  color: #fff; background: rgba(20, 20, 50, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.5); border-radius: 50%;
  touch-action: manipulation;
}
body.touch #rotFab { display: block; }
body.rot #rotFab { transform: translateX(-50%) rotate(90deg); }
body.layout #rotFab { display: none; }

/* controls dialog: compact when the frame is short (rotated phone / landscape phone) */
body.rot #settings .card, body.rot #settings .card h2 { padding-top: 8px; }
body.rot #settings .card { padding: 8px 14px; }
body.rot #settings .card h2 { margin-bottom: 4px; font-size: 16px; }
body.rot #settings .rows .row { padding: 2px 8px; font-size: 13px; }
body.rot #settings .keybtn { padding: 3px 6px; }
body.rot #settings .card .btns { margin-top: 8px; }
@media (max-height: 460px) {
  #settings .card { padding: 8px 14px; }
  #settings .card h2 { margin-bottom: 4px; font-size: 16px; }
  #settings .rows .row { padding: 2px 8px; font-size: 13px; }
  #settings .keybtn { padding: 3px 6px; }
  #settings .card .btns { margin-top: 8px; }
}

body.rot #keyRows { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
body.rot #settings .card { width: min(720px, 100%); }
@media (max-height: 460px) {
  #keyRows { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
  #settings .card { width: min(720px, 100%); }
}
