/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --navy:      #1a1a2e;
  --navy-mid:  #16213e;
  --navy-card: #0f3460;
  --red:       #e94560;
  --gold:      #f5a623;
  --parchment: #e8dcc8;
  --muted:     #a89b8c;
  --green:     #4caf50;
  --success:   #27ae60;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,0.5);
}

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

html, body {
  height: 100%;
  background: var(--navy);
  color: var(--parchment);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ── Typography ─────────────────────────────────────────────────────────────── */
.title-font { font-family: 'Cinzel', serif; }

h1 { font-size: 2rem; color: var(--gold); margin-bottom: .25rem; }
h2 { font-size: 1.5rem; color: var(--gold); margin-bottom: .5rem; }
h3 { font-size: 1.1rem; color: var(--parchment); }

/* ── Global layout ──────────────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.screen-center {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

/* ── App header ─────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  background: var(--navy-mid);
  border-bottom: 1px solid rgba(255,255,255,.07);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-title { font-family: 'Cinzel', serif; color: var(--gold); font-weight: 700; }

.header-right { display: flex; align-items: center; gap: .75rem; }

.user-name {
  font-size: .8rem;
  color: var(--muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .65rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, opacity .15s, background .15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--red);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #c73550; }

.btn-secondary {
  background: rgba(255,255,255,.1);
  color: var(--parchment);
  border: 1px solid rgba(255,255,255,.15);
}
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,.18); }

.btn-text {
  background: none;
  color: var(--muted);
  font-size: .8rem;
  padding: .25rem .5rem;
}
.btn-text:hover { color: var(--parchment); }

.btn-wide { width: 100%; margin-top: 1rem; padding: .85rem; font-size: 1rem; }

/* Action buttons grid */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  padding: .75rem 1rem 1rem;
}

.btn-action {
  background: var(--navy-card);
  color: var(--parchment);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: .75rem .5rem;
  font-size: .88rem;
}
.btn-action:hover:not(:disabled) { background: #1a4a8a; border-color: var(--gold); }

.btn-spell { background: #2d1b69; border-color: #7c3aed; }
.btn-spell:hover:not(:disabled) { background: #3d2080; }

.btn-flee { color: var(--muted); }
.btn-flee:hover:not(:disabled) { color: var(--red); border-color: var(--red); }

/* ── Auth screen ────────────────────────────────────────────────────────────── */
.auth-box {
  background: var(--navy-mid);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.auth-logo {
  font-size: 3.5rem;
  margin-bottom: .75rem;
  filter: drop-shadow(0 0 20px rgba(233,69,96,.5));
}

.tagline {
  color: var(--muted);
  font-style: italic;
  margin-bottom: 1.25rem;
}

.auth-desc {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.google-icon { flex-shrink: 0; }

/* ── Nickname screen ────────────────────────────────────────────────────────── */
.nickname-input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  color: var(--parchment);
  font-size: 1.1rem;
  font-family: 'Cinzel', serif;
  padding: .65rem .9rem;
  text-align: center;
  letter-spacing: .05em;
  margin-top: .75rem;
  outline: none;
  transition: border-color .15s;
}
.nickname-input:focus { border-color: var(--gold); }
.nickname-input::placeholder { color: rgba(255,255,255,.25); font-family: 'Inter', sans-serif; font-size: .9rem; letter-spacing: 0; }

.nickname-count {
  font-size: .72rem;
  color: var(--muted);
  text-align: right;
  margin-top: .25rem;
  opacity: .6;
}

/* ── Tutorial modal ─────────────────────────────────────────────────────────── */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.tutorial-modal {
  background: var(--navy-mid);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  margin: auto;
  box-shadow: var(--shadow);
}

.tutorial-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem .8rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: sticky;
  top: 0;
  background: var(--navy-mid);
  border-radius: 16px 16px 0 0;
  z-index: 1;
}

.tutorial-header h2 { margin: 0; font-size: 1.2rem; }

.tutorial-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 4px;
  line-height: 1;
}
.tutorial-close:hover { color: var(--parchment); background: rgba(255,255,255,.08); }

.tutorial-body {
  padding: 1rem 1.4rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.tut-section h3 {
  font-size: .95rem;
  color: var(--gold);
  margin-bottom: .45rem;
}

.tut-section p {
  font-size: .83rem;
  color: var(--muted);
  line-height: 1.6;
}

.tut-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: .5rem;
}

.tut-list li {
  font-size: .82rem;
  color: var(--muted);
  padding-left: .75rem;
  border-left: 2px solid rgba(255,255,255,.1);
  line-height: 1.5;
}

.tut-list li strong { color: var(--parchment); }

.tut-classes {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.tut-class {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 8px;
  padding: .6rem .85rem;
}

.tut-class strong {
  display: block;
  color: var(--parchment);
  font-size: .88rem;
  margin-bottom: .2rem;
}

.tut-class p {
  margin: 0;
  font-size: .78rem;
}

/* ── Dev mode ───────────────────────────────────────────────────────────────── */
.dev-mode-wrap { margin-top: 1rem; }

.dev-divider {
  font-size: .75rem;
  color: var(--muted);
  margin: .75rem 0 .6rem;
  opacity: .6;
}

.btn-dev {
  width: 100%;
  background: rgba(255,255,255,.06);
  color: var(--muted);
  border: 1px dashed rgba(255,255,255,.2);
  border-radius: var(--radius);
  padding: .55rem 1rem;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-dev:hover { background: rgba(255,255,255,.1); color: var(--parchment); }

.dev-note {
  font-size: .7rem;
  color: var(--muted);
  opacity: .5;
  margin-top: .35rem;
}

/* ── Class select ───────────────────────────────────────────────────────────── */
.date-tag {
  font-size: .8rem;
  color: var(--gold);
  letter-spacing: .05em;
  margin-bottom: 1rem;
  opacity: .85;
}

.class-cards {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-bottom: .5rem;
}

.class-card {
  background: var(--navy-mid);
  border: 2px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: left;
}

.class-card:hover  { border-color: rgba(245,166,35,.4); background: var(--navy-card); }
.class-card.selected {
  border-color: var(--gold);
  background: var(--navy-card);
  box-shadow: 0 0 16px rgba(245,166,35,.2);
}

.class-emoji { font-size: 2rem; margin-bottom: .25rem; }

.class-stats {
  display: flex;
  gap: 1rem;
  font-size: .82rem;
  color: var(--muted);
  margin: .35rem 0 .4rem;
}

.class-special {
  font-size: .83rem;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: .15rem;
}

.class-special-detail {
  font-size: .78rem;
  color: var(--muted);
}

/* ── HUD ────────────────────────────────────────────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  background: var(--navy-mid);
  border-bottom: 1px solid rgba(255,255,255,.07);
  font-size: .85rem;
  font-weight: 600;
}

.hud-floor { color: var(--gold); font-family: 'Cinzel', serif; font-size: .9rem; }

.hud-right {
  display: flex;
  gap: .75rem;
  align-items: center;
}

.hud-bar-track {
  height: 4px;
  background: rgba(255,255,255,.08);
}

.hud-bar {
  height: 100%;
  background: linear-gradient(90deg, #e94560, #f5a623);
  transition: width .4s ease;
  max-width: 100%;
}

.hud-inventory {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .3rem .75rem;
  background: rgba(0,0,0,.2);
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.inv-badge {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  padding: .1rem .5rem;
  font-size: .75rem;
}

.inv-label {
  color: var(--parchment);
  opacity: .85;
}

/* ── Enemy card ─────────────────────────────────────────────────────────────── */
.enemy-card {
  text-align: center;
  padding: 1.25rem 1rem .75rem;
  background: linear-gradient(180deg, var(--navy-mid) 0%, var(--navy) 100%);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.enemy-emoji {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: .3rem;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.6));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

.enemy-name {
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  color: var(--red);
  margin-bottom: .4rem;
}

.hp-track {
  height: 8px;
  background: rgba(255,255,255,.1);
  border-radius: 4px;
  overflow: hidden;
  width: 80%;
  margin: 0 auto .25rem;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #e94560, #ff6b6b);
  border-radius: 4px;
  transition: width .35s ease;
}

.enemy-hp-text { font-size: .78rem; color: var(--muted); }

.charge-warning {
  margin-top: .4rem;
  font-size: .8rem;
  font-weight: 700;
  color: #ff4444;
  background: rgba(255, 68, 68, .12);
  border: 1px solid rgba(255, 68, 68, .4);
  border-radius: 6px;
  padding: .25rem .75rem;
  display: inline-block;
  animation: pulse 0.7s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: .7; }
  to   { opacity: 1; }
}

/* ── Dice flash ─────────────────────────────────────────────────────────────── */
.dice-flash {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: .5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
}

.dice-val {
  background: var(--navy-card);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: .2rem .6rem;
  font-size: .95rem;
}

.dice-vs { color: var(--muted); font-size: .8rem; }

@keyframes fadeOut {
  0%   { opacity: 1; transform: scale(1); }
  60%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(.95); }
}

/* ── Combat log ─────────────────────────────────────────────────────────────── */
.combat-log {
  flex: 1;
  overflow-y: auto;
  padding: .6rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: .82rem;
  min-height: 80px;
  max-height: 180px;
}

.log-entry {
  color: var(--muted);
  animation: slideIn .2s ease;
  padding: .15rem .25rem;
  border-bottom: 1px solid rgba(255,255,255,.03);
  border-radius: 3px;
  font-size: .83rem;
}

.log-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,.1);
  margin: .35rem 0 .15rem;
}

/* Color-coded combat lines */
.log-player-hit {
  color: #f5c842;
  font-weight: 700;
}

.log-enemy-hit {
  color: #ff5a5a;
  font-weight: 700;
}

.log-warning {
  color: #ff9a3c;
  font-weight: 700;
}

.log-good {
  color: #4cdf80;
  font-weight: 600;
}

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

/* ── Loot screen ────────────────────────────────────────────────────────────── */
.loot-box {
  background: var(--navy-mid);
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 30px rgba(245,166,35,.15);
  animation: popIn .25s ease;
}

@keyframes popIn {
  from { transform: scale(.9); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.loot-found { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; letter-spacing: .08em; text-transform: uppercase; }

.loot-emoji { font-size: 3rem; margin: .5rem 0; }

.loot-desc { font-size: .85rem; color: var(--muted); margin: .5rem 0 1.25rem; }

.loot-btns { display: flex; gap: .75rem; justify-content: center; }
.loot-btns .btn { flex: 1; }

/* ── Summary / Dead / Victory ───────────────────────────────────────────────── */
.summary-box {
  background: var(--navy-mid);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.summary-icon { font-size: 3rem; margin-bottom: .5rem; }

.run-summary {
  text-align: left;
  margin: 1rem 0;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4rem 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-size: .88rem;
}

.summary-row span:first-child { color: var(--muted); }
.summary-row strong { color: var(--parchment); }
.summary-score strong { color: var(--gold); font-size: 1.1rem; }

.floor-squares {
  font-size: 1.1rem;
  letter-spacing: .05em;
  margin: .75rem 0 .5rem;
  text-align: center;
}

.run-summary-text {
  font-size: .85rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
  margin-top: .5rem;
}

.summary-btns {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  margin-top: 1rem;
}

/* ── Leaderboard ────────────────────────────────────────────────────────────── */
.lb-list { margin: .75rem 0; }

.lb-row {
  display: grid;
  grid-template-columns: 2rem 1fr 3.5rem 3rem 4.5rem;
  gap: .4rem;
  align-items: center;
  padding: .5rem .4rem;
  border-bottom: 1px solid rgba(255,255,255,.05);
  font-size: .82rem;
}

.lb-header {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid rgba(255,255,255,.15);
}

.lb-me {
  background: rgba(245,166,35,.08);
  border-left: 2px solid var(--gold);
  border-radius: 4px;
}

.lb-rank { font-size: .95rem; text-align: center; }

.lb-player {
  display: flex;
  align-items: center;
  gap: .4rem;
  overflow: hidden;
}

.lb-player span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.lb-avatar-placeholder {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--navy-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.lb-score { color: var(--gold); font-weight: 600; text-align: right; }
.lb-floors, .lb-class { color: var(--muted); }

.loading, .empty, .error { text-align: center; color: var(--muted); padding: 1.5rem 0; font-size: .88rem; }
.error { color: var(--red); }

/* ── Countdown ──────────────────────────────────────────────────────────────── */
.countdown-block {
  text-align: center;
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: .82rem;
}

.countdown {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: var(--gold);
  letter-spacing: .1em;
  margin-top: .25rem;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy-card);
  color: var(--parchment);
  padding: .6rem 1.2rem;
  border-radius: 20px;
  font-size: .85rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
  z-index: 100;
  border: 1px solid rgba(255,255,255,.1);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { border-color: var(--success); color: var(--success); }
.toast-error   { border-color: var(--red);     color: var(--red); }

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

/* ── Desktop / tablet layout ────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .screen-game { max-width: 480px; margin: 0 auto; }
  .class-cards { flex-direction: row; flex-wrap: wrap; }
  .class-card  { flex: 1 1 calc(33% - .5rem); min-width: 140px; }
}
