/* BusStopGame – KIO Colors + Light/Dark Toggle + Admin + Top Dropdowns */

@font-face {
  font-family: "KIOFont";
  src: url("/static/fonts/T-StarTW-Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --kio-black: #000000;
  --kio-white: #FFFFFF;
  --kio-gray: #DDDDDD;
  --kio-green: #55FC27;
  --kio-orange: #FF9F0A;
  --kio-red: #FF3B30;
  --bg: var(--kio-white);
  --fg: var(--kio-black);
  --surface: var(--kio-white);
  --surface-2: var(--kio-gray);
  --border-color: var(--kio-black);
  --border: 2px solid var(--border-color);
  --accent: var(--kio-green);
  --radius: 18px;
  --pill: 999px;
  --bottom-scale: 0.80;
}

:root[data-theme="dark"] {
  --bg: var(--kio-black);
  --fg: var(--kio-white);
  --surface: var(--kio-black);
  --surface-2: var(--kio-gray);
  --border-color: var(--kio-white);
  --border: 2px solid var(--border-color);
  --accent: var(--kio-green);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "KIOFont", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Anti-Select / Anti-Callout */
html, body, #wrap {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button, .cell, .resultOverlay, .resultText {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(10px, 2.2vw, 20px);
  display: flex;
  flex-direction: column;
  min-height: 100%;
  gap: clamp(10px, 2vw, 14px);
}

/* =========================
   ADMIN MODE (DEFAULT OFF)
   ========================= */
body:not(.admin-on) header {
  justify-content: center;
  align-items: center;
  border-bottom: none;
  padding-bottom: 0;
}

body:not(.admin-on) .title { display: none; }

body:not(.admin-on) .meta {
  justify-content: center;
  width: 100%;
}

body:not(.admin-on) .meta > :not(#adminToggleBtn) {
  display: none !important;
}

body:not(.admin-on) footer {
  display: none !important;
}

/* HEADER */
header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: var(--border);
}

.title {
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: 800;
  letter-spacing: 0.2px;
}

.meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 700;
}

/* =========================
   ADMIN BUTTON + PIN ENTRY
   ========================= */
@keyframes pinShake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.adminBtn {
  padding: 6px 12px;
  border-radius: var(--pill);
  border: var(--border);
  background: var(--surface);
  color: var(--fg);
  font-weight: 950;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
}

.adminBtn:active { transform: scale(0.99); }

.adminBtn.active {
  background: var(--accent);
  color: var(--kio-black);
}

.adminBtn.pin-entry {
  background: var(--kio-red);
  color: var(--kio-white);
}

.adminBtnLabel { display: inline-block; }

.adminPinInput {
  display: none;
  width: 5.2ch;
  text-align: center;
  border: none;
  outline: none;
  background: transparent;
  color: var(--kio-white);
  font-weight: 950;
  letter-spacing: 0.6ch;
  font-size: 12px;
  padding: 0;
  margin: 0;
}

.adminBtn.pin-entry .adminBtnLabel { display: none; }
.adminBtn.pin-entry .adminPinInput { display: inline-block; }

.adminBtn.pin-bad { animation: pinShake 240ms ease-in-out; }

/* =========================
   TOP DROPDOWN BUTTONS
   ========================= */
.topDropGroup {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.topBtn {
  padding: 6px 12px;
  border-radius: var(--pill);
  border: var(--border);
  background: var(--surface);
  color: var(--fg);
  font-weight: 950;
  cursor: pointer;
  touch-action: manipulation;
  min-width: 92px;
}

.topBtn:active { transform: scale(0.99); }

.topBtn.active {
  background: var(--accent);
  color: var(--kio-black);
}

.topDropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: min(320px, 78vw);
  border: var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

:root[data-theme="dark"] .topDropdown {
  box-shadow: 0 10px 30px rgba(0,0,0,0.38);
}

.topDropdownRow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.topDropdownKey {
  font-weight: 900;
  opacity: 0.85;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.topDropdownVal {
  font-weight: 950;
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

/* button inside dropdown (ROOMS) */
.dropActionBtn {
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: var(--border);
  background: var(--surface);
  color: var(--fg);
  font-weight: 950;
  cursor: pointer;
  touch-action: manipulation;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.dropActionBtn:active { transform: scale(0.99); }

.dropActionBtn:hover {
  background: var(--accent);
  color: var(--kio-black);
}

/* MAIN */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

/* Shared card look */
.card {
  border: var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

/* container scale */
.centerStack, .centerSolo { container-type: inline-size; }

/* ✅ Old square layout */
.centerStack {
  width: min(68vh, 560px, 92vw);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-rows: 2fr 1fr; /* ✅ 2/3 + 1/3 */
  gap: clamp(8px, 3cqw, 14px);
}

.centerSolo {
  width: min(68vh, 560px, 92vw);
  aspect-ratio: 1 / 1;
  display: grid;
}

.soloCard {
  width: 100%;
  height: 100%;
}

.centerScreen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 3cqw, 14px);
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3cqw, 16px);
}

/* Start area */
.centerScreen.startOnly {
  padding: 0;
  gap: 0;
}

.startButton {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.startLogoWrap {
  width: min(92%, 520px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
  user-select: none;
  padding-top: clamp(10px, 3.5cqw, 18px);
}

.startLogo {
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
  user-select: none;
}

.startLower {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: clamp(10px, 3.5cqw, 18px);
  z-index: 2;
}

.startText {
  font-weight: 950;
  font-size: clamp(14px, 5.2cqw, 28px);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  transition: transform 120ms ease;
  color: var(--fg);
}

.startButton:hover .startText { transform: scale(1.04); }
.startButton:active .startText { transform: scale(1.02); }

.holdFill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--accent);
  z-index: 1;
  transition: width 70ms linear;
}

.startButton.holding .startText { color: var(--kio-black); }

/* READY overlay in top card */
.readyOverlayTop {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2cqw, 10px);
  pointer-events: none;
  user-select: none;
  text-align: center;
  padding: clamp(10px, 3cqw, 16px);
}

.readyTitle {
  font-weight: 950;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  font-size: clamp(16px, 7cqw, 40px);
  line-height: 1.05;
}

.readySub {
  font-weight: 900;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  font-size: clamp(10px, 3.6cqw, 20px);
  opacity: 0.95;
}

.startButton.localReady .startLogoWrap,
.startButton.localReady .startLower { opacity: 0; }

.startButton.localReady .readyOverlayTop { display: flex; }

.startButton.localReady .readyOverlayTop { color: var(--kio-black); }
:root[data-theme="dark"] .startButton.localReady .readyOverlayTop { color: var(--kio-white); }

/* INFO screen */
.infoScreen {
  text-align: center;
  padding: clamp(12px, 4cqw, 20px);
  gap: clamp(10px, 3cqw, 16px);
}

.infoTitle {
  font-weight: 950;
  letter-spacing: 0.6px;
  font-size: clamp(16px, 6cqw, 30px);
}

.infoText {
  font-weight: 850;
  line-height: 1.25;
  max-width: 46ch;
  font-size: clamp(11px, 3.6cqw, 16px);
  opacity: 0.95;
}

/* Bottom card */
.bottomCard { position: relative; }

.oppHoldFill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--accent);
  z-index: 1;
  transition: width 70ms linear;
}

.bottomCard { --bscale: var(--bottom-scale); }

.bottomInner {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(10px, calc(3cqw * var(--bscale)), 14px);
}

.bottomTop {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.sessionTitle {
  font-weight: 950;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  font-size: clamp(12px, calc(4.2cqw * var(--bscale)), 18px);
  line-height: 1;
  text-align: right;
}

.bottomLayout {
  width: 100%;
  display: grid;
  grid-template-areas: "left center right";
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(8px, calc(3cqw * var(--bscale)), 14px);
  min-height: clamp(44px, calc(18cqw * var(--bscale)), 78px);
  position: relative;
}

#leftButtons { grid-area: left; }
#bottomSpacer { grid-area: center; }
#scoreColumn { grid-area: right; }

#oppReadyText {
  grid-area: center;
  position: relative;
  z-index: 3;
}

.bottomBottom { flex: 1; }

.leftButtons {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(8px, calc(3cqw * var(--bscale)), 14px);
}

.squareBtn {
  width: clamp(44px, calc(18cqw * var(--bscale)), 78px);
  aspect-ratio: 1 / 1;
  border-radius: clamp(10px, calc(3.2cqw * var(--bscale)), 14px);
  border: var(--border);
  background: var(--surface);
  color: var(--fg);
  display: grid;
  place-items: center;
  font-weight: 950;
  cursor: pointer;
  touch-action: manipulation;
}

.squareBtn:active { transform: scale(0.98); }

.squareBtn.active {
  background: var(--accent);
  color: var(--kio-black);
}

.squareBtnIcon {
  width: 62%;
  height: 62%;
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.scoreColumn {
  width: clamp(140px, calc(46cqw * var(--bscale)), 260px);
  height: clamp(44px, calc(18cqw * var(--bscale)), 78px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(4px, calc(1.8cqw * var(--bscale)), 10px);
}

.scoreBlock {
  width: 100%;
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  align-items: center;
  justify-items: end;
  text-align: right;
  gap: 2px;
}

.scoreLine1 {
  font-weight: 950;
  letter-spacing: 0.6px;
  font-size: clamp(12px, calc(4.2cqw * var(--bscale)), 18px);
  line-height: 1;
  min-height: 1em;
}

.scoreLine2, .scoreLine3 {
  font-weight: 900;
  font-size: clamp(10px, calc(3.4cqw * var(--bscale)), 14px);
  line-height: 1;
  opacity: 0.95;
}

.scoreLine2 span, .scoreLine3 span { font-weight: 950; }

.connBlock {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(6px, calc(2.2cqw * var(--bscale)), 10px);
}

.connDot {
  width: clamp(10px, calc(3.2cqw * var(--bscale)), 14px);
  height: clamp(10px, calc(3.2cqw * var(--bscale)), 14px);
  border-radius: 999px;
  background: var(--kio-orange);
  flex: 0 0 auto;
  border: none;
}

.connDot.online { background: var(--accent); }
.connDot.reconnecting { background: var(--kio-orange); }
.connDot.offline { background: var(--kio-red); }

.connMiniText {
  font-weight: 900;
  font-size: clamp(9px, calc(3cqw * var(--bscale)), 12px);
  line-height: 1;
  opacity: 0.95;
  text-transform: lowercase;
}

/* Opponent holding -> black text on green (light mode only) */
#centerBottom.oppHolding .scoreLine1,
#centerBottom.oppHolding .scoreLine2,
#centerBottom.oppHolding .scoreLine3,
#centerBottom.oppHolding .connMiniText,
#centerBottom.oppHolding .squareBtn,
#centerBottom.oppHolding .sessionTitle {
  color: var(--kio-black);
}

/* READY MODE */
@keyframes readyPulse {
  0% { transform: scale(1); opacity: 0.80; }
  50% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 0.80; }
}

.oppReadyText {
  width: 100%;
  text-align: center;
  font-weight: 950;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  line-height: 1;
  font-size: clamp(14px, calc(6.6cqw * var(--bottom-scale)), 30px);
  color: var(--kio-black);
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
  pointer-events: none;
  user-select: none;
}

#centerBottom.oppReady .oppReadyText { animation: readyPulse 0.9s ease-in-out infinite; }
#centerBottom.oppReady .scoreColumn { display: none; }

#centerBottom.oppReady #btnGetOpponent,
#centerBottom.oppReady #btnThemeSquare {
  display: none !important;
}

#centerBottom.oppReady .bottomLayout {
  grid-template-areas: "left center";
  grid-template-columns: auto 1fr;
}

#centerBottom.oppReady .sessionTitle { opacity: 0; }

/* Rahmen für PLAYING: Idle-Leiste oben + Board darunter (ein Rahmen) */
.playFrame {
  width: 100%;
  height: 100%;
  border: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

/* Idle-Leiste: fester Header oben */
.turnBox {
  flex: 0 0 auto;
  width: 100%;
  border: 0;
  border-bottom: var(--border);
  border-radius: 0;
  background: var(--surface);
  position: relative;
  overflow: hidden;
  min-height: clamp(44px, 12cqw, 74px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
}

.turnIdleFill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--idle-fill-color, var(--accent));
  z-index: 1;
  transition: width 80ms linear;
}

.turnLabelText {
  position: relative;
  z-index: 2;
}

/* Board-Bereich unter der Leiste */
.boardArea {
  flex: 1 1 auto;
  position: relative;
  background: var(--surface);
}

.boardArea .boardWrap {
  width: 100%;
  height: 100%;
  padding: clamp(10px, 3cqw, 16px);
  display: flex;
}

/* PLAYING */
.boardWrap {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(8px, 3cqw, 14px);
}

.cell {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: transparent;
  border: 2px solid var(--kio-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 950;
  font-size: clamp(28px, 16cqw, 86px);
  cursor: pointer;
  touch-action: manipulation;
}

.cell:hover {
  background: var(--accent);
  color: var(--kio-black);
}

.cell.disabled {
  cursor: default;
  background: transparent;
  color: var(--fg);
  opacity: 0.75;
}

.cell.disabled:hover { background: transparent; }

/* Result overlay */
.resultOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.78);
  pointer-events: none;
  padding: 18px;
}

:root[data-theme="dark"] .resultOverlay {
  background: rgba(0,0,0,0.72);
}

.resultText {
  font-size: clamp(16px, 6cqw, 30px);
  font-weight: 950;
  text-align: center;
}

/* Footer */
footer {
  padding-top: 8px;
  border-top: var(--border);
}

.small {
  font-size: 12px;
  opacity: 0.8;
}

/* DARKMODE FIX: keep white on green */
:root[data-theme="dark"] .startButton.holding .startText {
  color: var(--kio-white) !important;
}

:root[data-theme="dark"] #centerBottom.oppHolding .scoreLine1,
:root[data-theme="dark"] #centerBottom.oppHolding .scoreLine2,
:root[data-theme="dark"] #centerBottom.oppHolding .scoreLine3,
:root[data-theme="dark"] #centerBottom.oppHolding .connMiniText,
:root[data-theme="dark"] #centerBottom.oppHolding .squareBtn,
:root[data-theme="dark"] #centerBottom.oppHolding .sessionTitle {
  color: var(--kio-white) !important;
}

@keyframes turnPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(var(--pulse-scale, 1.02)); }
}
