/* ===== Base ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0a0a0a;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', 'Noto Sans SC',
    'Malgun Gothic', sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

/* CRITICAL: ensure hidden attribute works even when display is set via CSS */
[hidden] { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top), 10px) 14px 10px;
  background: #0a0a0a;
  border-bottom: 1px solid #1a1a1a;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}
.topbar-title { font-size: 14px; font-weight: 600; opacity: 0.8; }
.topbar-right {
  min-width: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}
.btn-host-end {
  background: #c62828; color: #fff; border: none;
  border-radius: 999px; padding: 6px 14px; font-size: 12px; font-weight: 700;
}
.btn-host-end:active { transform: scale(0.95); }
.lang-toggle { display: flex; gap: 6px; }
.lang-btn {
  background: #1a1a1a; color: #888;
  border: 1px solid #2a2a2a; border-radius: 999px;
  padding: 6px 12px; font-size: 12px; font-weight: 600;
}
.lang-btn.active { background: #2e7d32; color: #fff; border-color: #2e7d32; }
.conn-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; background: #e53935; transition: background 0.3s;
}
.conn-dot.connected { background: #43a047; }

/* ===== Screens ===== */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
}
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadein 0.35s ease;
  min-height: 0;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.card {
  width: 100%; max-width: 420px;
  background: #141414; border: 1px solid #242424;
  border-radius: 16px; padding: 22px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.big-title { text-align: center; font-size: 64px; margin: 0 0 10px; }
.card h2 { text-align: center; margin: 0 0 6px; font-size: 22px; }
.card h3 { margin: 20px 0 10px; font-size: 16px; color: #ccc; }
.muted { color: #888; font-size: 13px; text-align: center; }

.field-label {
  display: block; font-size: 12px; color: #aaa;
  margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.05em;
}
input[type="text"],
input[type="tel"] {
  width: 100%; padding: 14px 16px;
  background: #0a0a0a; color: #fff;
  border: 1px solid #333; border-radius: 10px;
  font-size: 16px; outline: none; transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="tel"]:focus { border-color: #4caf50; }

/* ===== Buttons ===== */
.btn {
  display: block; width: 100%; padding: 14px 16px;
  background: #2a2a2a; color: #fff; border: none;
  border-radius: 10px; font-size: 15px; font-weight: 600;
  transition: transform 0.08s, background 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: #2e7d32; }
.btn-primary:hover { background: #388e3c; }
.btn-secondary { background: #1565c0; }
.btn-danger { background: #c62828; }
.btn-ghost { background: transparent; border: 1px solid #333; }
.btn-small { padding: 8px 14px; font-size: 13px; width: auto; }
.btn-row { margin-top: 14px; }
.btn-stack { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }

.divider {
  margin: 22px 0 4px; text-align: center; position: relative;
  color: #666; font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%;
  width: 40%; height: 1px; background: #2a2a2a;
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

.error-msg { color: #ef5350; font-size: 13px; text-align: center; margin: 12px 0 0; min-height: 18px; }
.hint { font-size: 12px; color: #666; text-align: center; margin: 14px 0 0; }

/* ===== Lobby ===== */
.room-code-display {
  text-align: center; padding: 14px;
  background: #0a0a0a; border-radius: 12px; margin-bottom: 6px;
}
.room-code { font-size: 42px; font-weight: 800; letter-spacing: 0.2em; color: #4caf50; margin: 6px 0 2px; }
.room-password { font-size: 28px; font-weight: 800; letter-spacing: 0.4em; color: #ffb74d; margin: 0 0 10px; }
.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  padding: 12px 14px; background: #0a0a0a; border-radius: 10px;
  display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.player-list li .order-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: #333; color: #ccc; font-size: 11px; font-weight: 700;
}
.player-list li.host .order-num { background: #2e7d32; color: #fff; }
.player-list li .badge { font-size: 11px; color: #ffb74d; margin-left: auto; }
.player-list li.self { border: 1px solid #4caf50; }

/* ===== Crocodile game ===== */
.game-header {
  width: 100%; max-width: 420px;
  display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px;
}
.turn-indicator {
  background: #141414; border: 1px solid #242424;
  border-radius: 12px; padding: 10px 14px; flex: 1; text-align: center;
}
.turn-indicator .muted { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.current-player { font-size: 18px; font-weight: 700; color: #4caf50; margin-top: 2px; word-break: break-all; }
.remaining-count { font-size: 20px; font-weight: 800; color: #fff; margin-top: 2px; }

.croc-wrapper { width: 100%; max-width: 420px; display: flex; justify-content: center; padding: 10px 0; }
.croc {
  position: relative; width: 100%; aspect-ratio: 0.48; max-height: 60vh;
  background: linear-gradient(160deg, #3a8f3e 0%, #1b5e20 100%);
  border-radius: 40px 40px 30px 30px; overflow: hidden;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6), inset 0 0 0 4px #1b5e20;
}
.croc-eye { position: absolute; top: 3%; width: 12px; height: 6px; background: #000; border-radius: 50%; }
.croc-eye-left  { left: 30%; }
.croc-eye-right { right: 30%; }
.croc-mouth-inner {
  position: absolute; top: 8%; left: 5%; right: 5%; bottom: 4%;
  background: radial-gradient(ellipse at center, #5a1515 0%, #2a0808 100%);
  border-radius: 20px; overflow: hidden;
}

.tooth {
  position: absolute; width: 11%; aspect-ratio: 0.75;
  background: linear-gradient(180deg, #ffffff 0%, #dddddd 100%);
  border: none;
  border-radius: 50% 50% 40% 40% / 60% 60% 40% 40%;
  box-shadow: 0 3px 8px rgba(0,0,0,0.5), inset 0 -3px 6px rgba(0,0,0,0.2);
  transform: translate(-50%, -50%); transition: all 0.2s ease;
  padding: 0; cursor: pointer;
}
.tooth::after {
  content: ''; position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.6);
}
.tooth.pressed {
  background: transparent;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.6);
  border: 2px solid #2a0808; pointer-events: none;
}
.tooth.pressed::after { display: none; }
.tooth.pressing { animation: pressFlash 0.3s ease; }
@keyframes pressFlash {
  0%   { transform: translate(-50%, -50%) scale(1); }
  50%  { transform: translate(-50%, -50%) scale(1.3); filter: brightness(1.5); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
.tooth.disabled { cursor: not-allowed; opacity: 0.7; }
.tooth.bitten {
  background: linear-gradient(180deg, #ef5350 0%, #b71c1c 100%) !important;
  box-shadow: 0 0 20px rgba(239,83,80,0.8), 0 3px 8px rgba(0,0,0,0.5) !important;
  border: none !important;
  animation: bitePulse 0.5s ease 3;
  pointer-events: none;
}
.tooth.bitten::after { display: none; }
@keyframes bitePulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.25); }
}

.croc-tongue {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 50%; height: 22%;
  background: linear-gradient(180deg, #ff6e9c 0%, #d63a6b 100%);
  border: 3px solid #8b1538;
  border-radius: 50% 50% 45% 45%;
  color: #fff; font-size: 14px; font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 6px 14px rgba(0,0,0,0.6), inset 0 -4px 8px rgba(0,0,0,0.25);
  transition: transform 0.1s, opacity 0.2s; z-index: 5;
}
.croc-tongue:active { transform: translate(-50%, -50%) scale(0.95); }
.croc-tongue:disabled { opacity: 0.3; cursor: not-allowed; }

.turn-status {
  width: 100%; max-width: 420px; text-align: center;
  padding: 12px; color: #ccc; font-size: 14px; min-height: 40px;
}
.turn-status.your-turn { color: #4caf50; font-weight: 700; font-size: 16px; }

#screen-game.my-turn .croc {
  box-shadow: 0 20px 40px rgba(0,0,0,0.6), inset 0 0 0 4px #1b5e20,
    0 0 0 4px rgba(76,175,80,0.9), 0 0 40px rgba(76,175,80,0.6);
  animation: myTurnPulse 1.5s ease-in-out infinite;
}
@keyframes myTurnPulse {
  0%, 100% {
    box-shadow: 0 20px 40px rgba(0,0,0,0.6), inset 0 0 0 4px #1b5e20,
      0 0 0 4px rgba(76,175,80,0.9), 0 0 40px rgba(76,175,80,0.6);
  }
  50% {
    box-shadow: 0 20px 40px rgba(0,0,0,0.6), inset 0 0 0 4px #1b5e20,
      0 0 0 8px rgba(76,175,80,1), 0 0 60px rgba(76,175,80,0.9);
  }
}

.turn-alert {
  position: fixed; inset: 0;
  background: rgba(46,125,50,0.85); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; font-weight: 900; z-index: 200;
  pointer-events: none; animation: turnAlertAnim 1.2s ease forwards;
}
@keyframes turnAlertAnim {
  0%   { opacity: 0; transform: scale(0.9); }
  20%  { opacity: 1; transform: scale(1.05); }
  60%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

/* Bite overlay */
.bite-overlay {
  position: fixed; inset: 0;
  background: rgba(183,28,28,0.92); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; z-index: 200; pointer-events: none;
  animation: biteOverlayAnim 2.8s ease forwards;
}
.bite-overlay .bite-croc { font-size: 100px; animation: shake 0.6s ease; }
.bite-overlay .bite-name { font-size: 32px; font-weight: 900; }
.bite-overlay .bite-penalty { font-size: 24px; font-weight: 800; color: #ffeb3b; }
.bite-overlay .bite-text { font-size: 18px; color: #ffcdd2; }
@keyframes biteOverlayAnim {
  0%   { opacity: 0; }
  8%   { opacity: 1; }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== Result screen ===== */
.result-card { text-align: center; animation: scaleIn 0.4s ease; }
.bite-emoji { font-size: 80px; margin-bottom: 10px; animation: shake 0.6s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px) rotate(-5deg); }
  40% { transform: translateX(10px) rotate(5deg); }
  60% { transform: translateX(-8px) rotate(-3deg); }
  80% { transform: translateX(8px) rotate(3deg); }
}
.loser-name { font-size: 28px; font-weight: 800; color: #ef5350; margin: 10px 0 20px; }
.penalty-box {
  background: #0a0a0a; border: 2px solid #ef5350;
  border-radius: 14px; padding: 18px; margin: 10px 0;
}
.drinker-list {
  list-style: none; padding: 0; margin: 10px 0;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.drinker-list li {
  background: #2e1010; border: 1px solid #ef5350; color: #ffcdd2;
  padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 700;
}
.penalty-text { font-size: 22px; font-weight: 800; color: #ffeb3b; margin-top: 12px; }

/* ===== Ended / Stats screen ===== */
.ended-header { text-align: center; margin-bottom: 14px; }
.ended-header .big-title { font-size: 56px; margin-bottom: 6px; }
.stats-total {
  background: #0a0a0a; border: 2px solid #ffb74d;
  border-radius: 14px; padding: 18px; text-align: center; margin: 14px 0;
}
.stats-total-value { font-size: 38px; font-weight: 900; color: #ffb74d; margin-top: 4px; }
.stats-total-value .unit { font-size: 18px; color: #aaa; margin-left: 4px; }
.stats-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.stats-list li {
  background: #0a0a0a; border: 1px solid #242424;
  border-radius: 10px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.stats-list li.top { border-color: #ffb74d; background: linear-gradient(90deg, #1a0e00 0%, #0a0a0a 100%); }
.stats-rank {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: #333; font-size: 13px; font-weight: 800; flex-shrink: 0;
}
.stats-list li.top .stats-rank { background: #ffb74d; color: #000; }
.stats-info { flex: 1; min-width: 0; }
.stats-name { font-size: 15px; font-weight: 700; color: #fff; }
.stats-detail { font-size: 11px; color: #888; margin-top: 2px; }
.stats-glasses { font-size: 20px; font-weight: 900; color: #ffb74d; white-space: nowrap; }
.stats-glasses .unit { font-size: 12px; color: #888; margin-left: 2px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: #2a2a2a; color: #fff; padding: 12px 24px;
  border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6); z-index: 100;
  animation: toastSlide 0.3s ease;
}
@keyframes toastSlide {
  from { transform: translate(-50%, 30px); opacity: 0; }
  to   { transform: translateX(-50%); opacity: 1; }
}

@media (min-width: 480px) { .card { padding: 28px; } }
