:root {
  color-scheme: dark;
  --accent-1: #ffcf4d;
  --accent-2: #ff7a59;
  --accent-3: #52e0c4;
  --danger: #ff5c5c;
  --ink: #0b0e1a;
  --panel-bg: rgba(12, 16, 32, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f4f6ff;
  --text-dim: #b9c0d9;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--ink);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Overlays / panels ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: clamp(16px, 3vh, 32px) clamp(20px, 5vw, 36px);
  text-align: center;
  color: var(--text);
  max-width: min(92vw, 420px);
  max-height: 92vh;
  overflow-y: auto;
}

.title {
  font-size: clamp(1.6rem, 7vw, 2.6rem);
  margin: 0 0 4px;
  letter-spacing: 1px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 24px rgba(255, 127, 80, 0.25);
}
.title-dot { color: var(--accent-3); -webkit-text-fill-color: var(--accent-3); }

.overlay-title {
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  margin: 0 0 14px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 0 0 clamp(14px, 3vh, 20px);
  color: var(--text-dim);
  font-size: clamp(0.75rem, 1.6vw, 0.9rem);
}

.btn {
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.5px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  padding: 12px 22px;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  box-shadow: 0 6px 18px rgba(255, 122, 89, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
  margin-bottom: 10px;
}
.btn:active { transform: scale(0.96); filter: brightness(0.95); }
.btn:hover { filter: brightness(1.06); }

.btn-start { background: linear-gradient(135deg, var(--accent-3), #2fb8a0); }
.btn-mode { background: rgba(255,255,255,0.08); color: var(--text); box-shadow: none; }
.btn-mute {
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
  box-shadow: none;
  font-size: 0.8rem;
  padding: 8px 16px;
}

.overlay-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

.credit-badge {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  pointer-events: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  white-space: nowrap;
}
.credit-badge strong { color: var(--accent-3); font-weight: 800; }
.credit-badge:hover { color: var(--text); }

/* ---------- Auth screen ---------- */

.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.btn-tab {
  flex: 1;
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  padding: 10px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
  cursor: pointer;
}
.btn-tab.active {
  background: linear-gradient(135deg, var(--accent-3), #2fb8a0);
  color: var(--ink);
}

.auth-form { display: flex; flex-direction: column; text-align: left; }
.field-label {
  display: block;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.field-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
.field-label input:focus { outline: 2px solid var(--accent-3); }

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin: -4px 0 10px;
}

.photo-preview-wrap { display: flex; justify-content: center; margin-bottom: 12px; }
.photo-preview-wrap img {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent-3);
}

/* ---------- Menu ---------- */

.my-fighter { margin-bottom: 18px; }
.my-photo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent-1);
  margin-bottom: 8px;
}
.my-name { font-weight: 800; font-size: 1.1rem; }
.my-record { color: var(--text-dim); font-size: 0.85rem; }

.difficulty-select { margin-top: 4px; }
.difficulty-label {
  display: block;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.difficulty-buttons { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.btn-diff {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  box-shadow: none;
  padding: 8px 16px;
  margin-bottom: 0;
  width: auto;
  flex: 1;
}
.btn-diff.active {
  background: linear-gradient(135deg, var(--accent-3), #2fb8a0);
  color: var(--ink);
}

/* ---------- Queue ---------- */

.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent-3);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ---------- VS reveal ---------- */

.vs-row { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 18px; }
.vs-fighter { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; }
.vs-photo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent-1);
}
.vs-name { font-weight: 700; font-size: 0.85rem; word-break: break-word; }
.vs-badge {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent-2);
  text-shadow: 0 2px 10px rgba(255,122,89,0.4);
}
.vs-countdown {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent-3);
}

/* ---------- Match screen (landscape) ---------- */

.match-screen {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, #1a1030 0%, #0b0e1a 70%);
  z-index: 10;
  overflow: hidden;
}

.fighter-hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 12;
}
.fighter-hud-left { left: max(10px, env(safe-area-inset-left)); align-items: flex-start; }
.fighter-hud-right { right: max(10px, env(safe-area-inset-right)); align-items: flex-end; }

.hearts { display: flex; gap: 3px; }
.heart {
  position: relative;
  width: 18px;
  height: 16px;
}
.heart svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.heart .heart-bg { fill: rgba(255,255,255,0.15); }
.heart .heart-fill { fill: var(--accent-2); }
.heart .heart-fill-clip { overflow: hidden; position: absolute; inset: 0; }

.stamina-dots { display: flex; gap: 3px; }
.stamina-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  transition: background 0.15s ease;
}
.stamina-dot.lit { background: var(--accent-3); }

.opponent-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(56vh, 80vw);
  height: min(56vh, 80vw);
  border-radius: 50%;
  overflow: hidden;
  border: 6px solid;
  border-image: linear-gradient(135deg, var(--accent-1), var(--accent-2), var(--accent-1)) 1;
  box-shadow: 0 0 0 3px var(--ink), 0 0 40px rgba(255, 207, 77, 0.25), 0 20px 50px rgba(0,0,0,0.6);
}
.opponent-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.3s ease;
}
.opponent-frame[data-tier="2"] .opponent-photo { filter: saturate(0.6) brightness(0.85); }
.opponent-frame[data-tier="3"] .opponent-photo {
  filter: saturate(0.3) brightness(0.7) contrast(1.1);
  animation: dazed 2.2s ease-in-out infinite;
}
@keyframes dazed {
  0%, 100% { transform: rotate(-1deg); }
  50% { transform: rotate(1deg); }
}

.overlay-layer {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-size: 58% 58%;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.overlay-layer.show { opacity: 1; }

.hit-flash {
  position: absolute;
  inset: 0;
  background: rgba(255, 60, 60, 0.55);
  opacity: 0;
  pointer-events: none;
}
.hit-flash.flash { animation: hitflash 0.25s ease-out; }
@keyframes hitflash {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

.opponent-frame.shake { animation: hitshake 0.3s ease; }
@keyframes hitshake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(calc(-50% - 6px), -50%); }
  50% { transform: translate(calc(-50% + 5px), -50%); }
  75% { transform: translate(calc(-50% - 3px), -50%); }
}

.corner-btn {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 15;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.corner-btn:active { filter: brightness(1.3); transform: scale(0.94); }
.corner-tl { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); background: linear-gradient(135deg, var(--accent-1), var(--accent-2)); border: none; color: var(--ink); }
.corner-tr { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); background: linear-gradient(135deg, var(--accent-1), var(--accent-2)); border: none; color: var(--ink); }
.corner-bl { bottom: max(12px, env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); }
.corner-br { bottom: max(12px, env(safe-area-inset-bottom)); right: max(12px, env(safe-area-inset-right)); }

.btn-icon.match-forfeit {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 15;
}

.opponent-disconnect-banner {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--accent-1);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  z-index: 16;
}

/* ---------- Match end ---------- */

.matchend-record { color: var(--text-dim); margin-bottom: 16px; font-size: 0.95rem; }

/* ---------- Rotate hint ---------- */

.rotate-icon {
  font-size: 3rem;
  animation: spin 1.6s linear infinite;
  margin-bottom: 12px;
}
#rotate-hint {
  z-index: 40;
  background: rgba(6, 8, 16, 0.94);
  flex-direction: column;
  color: var(--text);
  text-align: center;
}
#rotate-hint p { max-width: 260px; color: var(--text-dim); }

/* Only show the rotate hint on portrait viewports */
@media (orientation: landscape) {
  #rotate-hint { display: none !important; }
}

@media (max-height: 420px) {
  .corner-btn { width: 52px; height: 52px; font-size: 1.3rem; }
  .credit-badge { font-size: 0.55rem; padding: 3px 9px; }
}
