/* ── Reset / base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gb-body:        #C4BFAF;
  --gb-body-dark:   #A8A49A;
  --gb-shadow:      #7A7670;
  --gb-screen-bg:   #2A2A2A;
  --gb-screen-lcd:  #0F380F;
  --gb-dpad:        #1C1C1C;
  --gb-btn-ab:      #7A1928;
  --gb-btn-ab-hi:   #9E2235;
  --gb-btn-sys:     #5A5560;
  --gb-text:        #3A3530;
  --gb-brand:       #4A3060;
  --gb-led-on:      #2ECC40;
  --gb-led-off:     #1A4A20;
  --status-ok:      #2ECC40;
  --status-err:     #FF4444;
  --status-idle:    #555;
}

html, body {
  height: 100%;
  background: #0e161c;
  font-family: Verdana, Geneva, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

/* ── Page layout ────────────────────────────────────────────────────────────── */
html, body { overflow: hidden; } /* no page scroll — Game Boy + chat fill the viewport */

.page {
  height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  padding: 24px 20px;
  gap: 24px;
  overflow: hidden;
}

/* ── Chat panel ─────────────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  min-width: 220px;
  height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #33454f;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #0e4a46;
  border-bottom: 1px solid #0e544f;
  flex-shrink: 0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  font-weight: 700;
  color: #eef7f4;
  letter-spacing: 0.03em;
}

.chat-twitch-icon {
  width: 16px;
  height: 16px;
  color: #9147ff;
  flex-shrink: 0;
}

.chat-live-badge {
  margin-left: auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #eae5d6;
  background: #0f181f;
  border: 1px solid #a8cc3e;
  padding: 2px 6px;
}

/* Clips the Twitch iframe's chat input bar off the bottom */
.chat-frame-clip {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.chat-frame-clip iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  /* Taller than container so the ~52px input bar slides below the fold */
  height: calc(100% + 52px);
  border: none;
}

/* ── Input panel ────────────────────────────────────────────────────────────── */
.input-panel {
  flex: 0 0 290px;
  height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #33454f;
  background: #1d2a33;
}

.input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #16212a;
  border-bottom: 1px solid #33454f;
  flex-shrink: 0;
  gap: 8px;
}

.input-header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.input-title {
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #eef7f4;
}

.input-total {
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  color: #93a3ac;
  font-variant-numeric: tabular-nums;
}

.lock-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #93a3ac;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.lock-btn:hover { background: #24333d; color: #eef7f4; }
.lock-btn.play-disabled { color: #e0918a; }
.lock-icon { width: 16px; height: 16px; }

/* Mode toggle button */
.mode-btn {
  background: rgba(95,201,188,0.12);
  border: 1px solid rgba(95,201,188,0.3);
  cursor: pointer;
  padding: 3px 7px;
  color: #5fc9bc;
  font-family: 'Courier New', Courier, monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}
.mode-btn:hover { background: rgba(95,201,188,0.22); }
.mode-btn.democratic {
  background: rgba(168,204,62,0.14);
  border-color: rgba(168,204,62,0.4);
  color: #b6e24a;
}
.mode-btn.democratic:hover { background: rgba(168,204,62,0.24); }

/* ── Vote panel (democratic mode only) ──────────────────────────────────────── */
.vote-panel {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 10px;
  border-bottom: 1px solid #33454f;
  background: #16212a;
  flex-shrink: 0;
}
.vote-panel.visible { display: flex; }

.vote-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.vote-status-label {
  font-family: 'Courier New', Courier, monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #b6e24a;
  text-transform: uppercase;
}
.vote-countdown {
  font-size: 11px;
  font-weight: 700;
  color: #eef7f4;
  font-variant-numeric: tabular-nums;
  font-family: 'Courier New', Courier, monospace;
}
.vote-countdown.ending { color: #e0918a; }

.vote-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.vote-row {
  display: grid;
  grid-template-columns: 48px 1fr 28px;
  align-items: center;
  gap: 6px;
  animation: entry-in 0.15s ease-out;
}
.vote-row-btn {
  font-family: 'Courier New', Courier, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 5px;
  text-align: center;
}
.vote-bar-track {
  height: 8px;
  background: #0f181f;
  overflow: hidden;
}
.vote-bar-fill {
  height: 100%;
  background: #a8cc3e;
  transition: width 0.3s ease-out;
}
.vote-row.winner .vote-bar-fill { background: #b6e24a; }
.vote-count {
  font-size: 9px;
  font-weight: 700;
  color: #93a3ac;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: 'Courier New', Courier, monospace;
}

/* Feed scroll area */
.input-feed {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: #33454f transparent;
}
.input-feed::-webkit-scrollbar { width: 4px; }
.input-feed::-webkit-scrollbar-track { background: transparent; }
.input-feed::-webkit-scrollbar-thumb { background: #33454f; }

/* Individual input entries */
.input-entry {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 12px;
  border-bottom: 1px solid #16212a;
  animation: entry-in 0.15s ease-out;
}
.input-entry:last-child { border-bottom: none; }

@keyframes entry-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.entry-time {
  font-size: 10px;
  color: #8fa3ac;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-family: 'Courier New', Courier, monospace;
}

.entry-player {
  font-weight: 700;
  font-size: 11px;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #eae5d6;
}

.entry-btn {
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  white-space: nowrap;
  text-align: center;
  min-width: 36px;
}

/* Button badge colours */
.btn-badge-A      { background: #5a1020; color: #ff6b6b; }
.btn-badge-B      { background: #3a1020; color: #cc4466; }
.btn-badge-UP,
.btn-badge-DOWN,
.btn-badge-LEFT,
.btn-badge-RIGHT  { background: #0d2a3a; color: #4db8e8; }
.btn-badge-START  { background: #3a3000; color: #f1c40f; }
.btn-badge-SELECT { background: #222230; color: #8888aa; }

/* ── Play disabled overlay on Game Boy ───────────────────────────────────────── */
.play-disabled-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.play-disabled-overlay.visible { opacity: 1; pointer-events: auto; }

.play-disabled-label {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #f4efe1;
  background: rgba(224, 145, 138, 0.85);
  padding: 8px 18px;
}

/* ── Responsive: stack vertically on narrow screens ─────────────────────────── */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .page {
    flex-direction: column;
    height: auto;
    overflow: visible;
    padding: 16px 12px;
  }
  .chat-panel {
    width: 100%;
    height: 360px;
  }
  .input-panel {
    width: 100%;
    flex: 0 0 auto;
    height: 300px;
  }
}

/* ── Scale wrapper – keeps correct height when GB is scaled down ────────────── */
.gameboy-wrapper {
  transform-origin: top center;
}

/* ── Game Boy body ──────────────────────────────────────────────────────────── */
.gameboy {
  width: 360px;
  position: relative;
  background: var(--gb-body);
  border-radius: 10px 10px 0 0;
  padding: 16px 16px 0;
  position: relative;
  box-shadow:
    0 4px 0 var(--gb-body-dark),
    0 8px 0 var(--gb-shadow),
    0 16px 40px rgba(0,0,0,0.6);
  /* Characteristic Game Boy bottom curve */
  border-bottom-left-radius:  50px 30px;
  border-bottom-right-radius: 10px 5px;
  border-bottom: 4px solid var(--gb-shadow);
  padding-bottom: 24px;
}

/* Angled bottom-left notch (DMG-style) */
.gameboy::before {
  content: '';
  position: absolute;
  bottom: -4px; left: 0;
  width: 70px; height: 40px;
  background: var(--gb-body-dark);
  border-radius: 0 0 0 50px;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

/* ── Top strip (LED + brand) ────────────────────────────────────────────────── */
.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.power-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gb-led-off);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
  transition: background 0.3s, box-shadow 0.3s;
}
.led.on {
  background: var(--gb-led-on);
  box-shadow: 0 0 6px var(--gb-led-on), inset 0 1px 2px rgba(255,255,255,0.3);
}

.led-label {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--gb-text);
  opacity: 0.7;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}
.brand-nintendo {
  font-size: 8px;
  color: var(--gb-brand);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand-gameboy {
  font-size: 18px;
  font-weight: 900;
  color: var(--gb-brand);
  letter-spacing: -0.02em;
}

/* ── Screen housing ─────────────────────────────────────────────────────────── */
.screen-housing {
  background: var(--gb-screen-bg);
  border-radius: 6px 6px 30px 6px;
  padding: 10px 12px 14px;
  margin-bottom: 14px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.6);
}

.screen-label-top {
  font-size: 6px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #888;
  text-align: center;
  margin-bottom: 8px;
}

.screen-bezel {
  background: #111;
  border-radius: 4px;
  padding: 8px;
}

.screen-inner {
  position: relative;
  aspect-ratio: 10 / 9; /* 160:144 */
  background: var(--gb-screen-lcd);
  border-radius: 2px;
  overflow: hidden;
}

.screen-inner video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
}

.stream-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 56, 15, 0.88);
  color: #8BAC0F;
  font-size: 11px;
  font-family: monospace;
  letter-spacing: 0.05em;
  transition: opacity 0.4s;
  pointer-events: none;
}
.stream-overlay.hidden { opacity: 0; }

/* ── Controls row ───────────────────────────────────────────────────────────── */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 4px;
}

/* ── D-Pad ──────────────────────────────────────────────────────────────────── */
.dpad-area { flex: 0 0 auto; }

.dpad {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.dpad-row {
  display: flex;
  gap: 0;
}

.dpad-corner {
  width: 38px;
  height: 38px;
  background: transparent;
}

.dpad-btn {
  width: 38px;
  height: 38px;
  background: var(--gb-dpad);
  border: none;
  cursor: pointer;
  position: relative;
  outline: none;
  border-radius: 2px;
  transition: background 0.07s, transform 0.07s;
  -webkit-tap-highlight-color: transparent;
}

/* Arrow glyphs via ::after */
.dpad-btn::after {
  content: '';
  display: block;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  border: 6px solid transparent;
}
.dpad-up::after    { border-bottom-color: #555; margin-top: -3px; }
.dpad-down::after  { border-top-color:    #555; margin-top:  3px; }
.dpad-left::after  { border-right-color:  #555; margin-left: -3px; }
.dpad-right::after { border-left-color:   #555; margin-left:  3px; }

.dpad-center {
  width: 38px;
  height: 38px;
  background: var(--gb-dpad);
  cursor: default;
  border-radius: 2px;
}

.dpad-btn:active,
.dpad-btn.active {
  background: #111;
  transform: scale(0.88);
}
.dpad-btn:active::after,
.dpad-btn.active::after {
  border-bottom-color: #8BAC0F;
  border-top-color:    #8BAC0F;
  border-right-color:  #8BAC0F;
  border-left-color:   #8BAC0F;
}
.dpad-up.active::after    { border-top-color:    transparent; border-right-color: transparent; border-left-color: transparent; border-bottom-color: #8BAC0F; }
.dpad-down.active::after  { border-bottom-color: transparent; border-right-color: transparent; border-left-color: transparent; border-top-color:    #8BAC0F; }
.dpad-left.active::after  { border-left-color:   transparent; border-top-color:   transparent; border-bottom-color: transparent; border-right-color: #8BAC0F; }
.dpad-right.active::after { border-right-color:  transparent; border-top-color:   transparent; border-bottom-color: transparent; border-left-color:  #8BAC0F; }

/* ── Center info ────────────────────────────────────────────────────────────── */
.controls-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.status-row {
  display: flex;
  gap: 12px;
}

.status-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-idle);
  transition: background 0.3s, box-shadow 0.3s;
}
.status-dot.connected  { background: var(--status-ok);  box-shadow: 0 0 4px var(--status-ok); }
.status-dot.error,
.status-dot.disconnected { background: var(--status-err); }
.status-dot.connecting { background: #F5A623; animation: pulse 1s infinite; }

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

.status-label {
  font-size: 6px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--gb-text);
  opacity: 0.6;
}

.viewer-count {
  display: flex;
  align-items: baseline;
  gap: 3px;
  color: var(--gb-text);
  font-size: 11px;
  font-weight: 700;
}

.viewer-label {
  font-size: 7px;
  font-weight: 400;
  opacity: 0.6;
  letter-spacing: 0.05em;
}

/* ── A/B buttons ────────────────────────────────────────────────────────────── */
.ab-area { flex: 0 0 auto; }

.ab-cluster {
  transform: rotate(-22deg);
}

.ab-pair {
  display: flex;
  gap: 10px;
  align-items: center;
}

.ab-button-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ab-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  color: rgba(255,255,255,0.5);
  background: var(--gb-btn-ab);
  box-shadow:
    0 4px 0 #4A0810,
    0 5px 8px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.15);
  outline: none;
  transition: transform 0.07s, box-shadow 0.07s, background 0.07s;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0;
}

.ab-btn:active,
.ab-btn.active {
  background: #5A1018;
  box-shadow:
    0 1px 0 #4A0810,
    0 2px 4px rgba(0,0,0,0.5),
    inset 0 2px 4px rgba(0,0,0,0.4);
  transform: translateY(3px) scale(0.94);
}

/* ── Select / Start ─────────────────────────────────────────────────────────── */
.sys-row {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 12px;
}

.sys-btn-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: rotate(-22deg);
}

.sys-btn {
  width: 44px;
  height: 13px;
  border-radius: 7px;
  border: none;
  background: var(--gb-btn-sys);
  box-shadow: 0 3px 0 #3A3440, inset 0 1px 0 rgba(255,255,255,0.12);
  cursor: pointer;
  outline: none;
  transition: transform 0.07s, box-shadow 0.07s;
  -webkit-tap-highlight-color: transparent;
}

.sys-btn:active,
.sys-btn.active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #3A3440, inset 0 1px 2px rgba(0,0,0,0.4);
}

.sys-label {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--gb-text);
  opacity: 0.65;
}

/* ── Speaker grill ──────────────────────────────────────────────────────────── */
.speaker-area {
  display: flex;
  justify-content: flex-end;
  padding-right: 8px;
  margin-bottom: 12px;
}

.speaker-grill {
  width: 56px;
  height: 40px;
  background-image: radial-gradient(circle, var(--gb-shadow) 1.5px, transparent 1.5px);
  background-size: 7px 7px;
  opacity: 0.6;
}

/* ── Keyboard hint ──────────────────────────────────────────────────────────── */
.kb-hint {
  text-align: center;
  font-size: 7px;
  letter-spacing: 0.06em;
  color: var(--gb-text);
  opacity: 0.4;
  padding-bottom: 4px;
  font-family: monospace;
}

