:root {
  --bg: #0d0f14;
  --bg-card: #161a22;
  --bg-elevated: #1e2430;
  --border: #2a3140;
  --gold: #c9a227;
  --gold-dim: #8a7020;
  --text: #e8e4dc;
  --text-muted: #8b919e;
  --danger: #c44;
  --success: #4a9;
  --safe: #3a7;
  --mystery: #7a6ac4;
  --radius: 14px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(201, 162, 39, 0.08), transparent),
    var(--bg);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
}

/* Header */
.app-header {
  padding: calc(12px + var(--safe-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 15, 20, 0.92);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.app-header p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Main content */
.screen-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  -webkit-overflow-scrolling: touch;
}

.screen {
  display: none;
  animation: fadeIn 0.2s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 12px;
}

/* Passport */
.passport-hero {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--bg-elevated), #2a3520);
  border: 2px solid var(--gold-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
}

.passport-name {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.passport-class {
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}

.passport-meta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.passport-meta span {
  display: block;
  margin-top: 2px;
}

.bio {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Stats grid */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-item {
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-wide {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
}

.hp-bar-wrap {
  flex: 1;
  margin-left: 12px;
}

.hp-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--danger), #e66);
  border-radius: 4px;
  transition: width 0.3s;
}

.pack-fill {
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
}

.pack-fill.over {
  background: linear-gradient(90deg, var(--danger), #f55);
}

.sleep-fill {
  background: linear-gradient(90deg, #2a4a6a, #5a9fd4);
}

/* Turn / my turn */
.card-turn {
  border-color: var(--gold-dim);
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.06), var(--bg-card));
}

.btn-turn {
  width: 100%;
  margin-top: 12px;
  padding: 16px;
  font-size: 17px;
  background: linear-gradient(180deg, #e0b830, var(--gold));
  color: #1a1408;
  border: none;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(201, 162, 39, 0.25);
}

.btn-turn:active {
  transform: scale(0.98);
}

.turn-active {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 4px;
}

.turn-steps {
  font-size: 48px;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
  min-width: 64px;
  text-align: center;
}

.turn-label {
  font-size: 14px;
  font-weight: 600;
}

.turn-dice {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.turn-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.turn-banner {
  text-align: center;
  border-color: var(--gold-dim);
  color: var(--gold);
}

.hint-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.4;
}

.sleep-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.inv-summary {
  border-color: var(--gold-dim);
}

.inv-essential {
  background: rgba(201, 162, 39, 0.05);
  margin: 0 -16px;
  padding: 12px 16px;
  border-radius: 8px;
}

.hidden { display: none !important; }

  padding: 18px;
  font-size: 18px;
  margin-top: 8px;
}

.welcome-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.welcome-text {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.55;
  text-align: center;
}

.version-tag {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 16px;
  opacity: 0.6;
}


/* === Character creation === */
.create-screen {
  min-height: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  overflow-y: auto;
}

.create-logo {
  font-size: 32px;
  font-weight: 800;
  color: var(--gold);
  text-align: center;
  letter-spacing: 0.08em;
}

.create-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  margin-bottom: 8px;
}

.field-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 17px;
  margin-bottom: 20px;
}

.field-input:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.btn-full { width: 100%; margin-bottom: 10px; }

.class-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.class-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 10px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}

.class-card.selected {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
}

.class-card-icon { font-size: 28px; }
.class-card-name { font-weight: 700; font-size: 14px; }
.class-card-meta { font-size: 10px; color: var(--text-muted); line-height: 1.3; }

.path-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.path-btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.path-btn.active {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.12);
  color: var(--gold);
}

.avatar-grid {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.avatar-pick {
  width: 52px;
  height: 52px;
  font-size: 26px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
}

.avatar-pick.selected {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.1);
}

.avatar-lg {
  width: 72px;
  height: 72px;
  font-size: 36px;
}

/* Passport params */
.param-list { display: flex; flex-direction: column; gap: 0; }

.param-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.param-row:last-child { border-bottom: none; }

.param-key { color: var(--text-muted); }
.param-val { font-weight: 700; }
.hp-val { color: #e88; }
.mana-val { color: #6af; }

/* Abilities & choices */
.ability-fixed { opacity: 1; }
.ability-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.card-locked { opacity: 0.55; }

.choice-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  line-height: 1.4;
}

.choice-btn:active { border-color: var(--gold); }

.choice-spell { margin-bottom: 8px; }

.picked-badge {
  padding: 10px 14px;
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid var(--gold-dim);
  border-radius: 10px;
  font-weight: 600;
  color: var(--gold);
}

/* Spells */
.spell-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.spell-item:last-child { border-bottom: none; }

.spell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.spell-cost {
  font-size: 12px;
  color: #6af;
  font-weight: 600;
}

.spell-desc { font-size: 12px; color: var(--text-muted); }

.spell-fixed { border-left: 3px solid var(--gold); padding-left: 10px; }



/* XP */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  padding: 8px 16px;
  margin-bottom: 16px;
}

.level-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--gold);
}

.level-info strong {
  display: block;
  font-size: 14px;
}

.level-info span {
  font-size: 12px;
  color: var(--text-muted);
}

.xp-bar-wrap {
  margin: 12px 0;
}

.xp-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.xp-bar {
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 5px;
  transition: width 0.4s;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-gold {
  background: var(--gold);
  color: #1a1408;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* Abilities */
.ability-list {
  list-style: none;
}

.ability-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.ability-item:last-child {
  border-bottom: none;
}

.ability-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.ability-locked {
  opacity: 0.45;
}

/* Inventory */
.inv-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.inv-item:last-child {
  border-bottom: none;
}

.inv-icon {
  width: 40px;
  height: 40px;
  background: var(--bg-elevated);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.inv-name {
  font-weight: 600;
  font-size: 14px;
}

.inv-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.inv-qty {
  margin-left: auto;
  font-weight: 700;
  color: var(--gold);
  font-size: 14px;
}

.type-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  margin-top: 4px;
}

/* Quests */
.quest-card {
  border-left: 3px solid var(--gold);
}

.quest-card.completed {
  border-left-color: var(--success);
  opacity: 0.75;
}

.quest-status {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
}

.quest-card.completed .quest-status {
  color: var(--success);
}

.quest-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.quest-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.objective {
  font-size: 12px;
  padding: 4px 0;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.objective.done {
  color: var(--text-muted);
  text-decoration: line-through;
}

.reward {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--gold-dim);
}

/* Map */
.map-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/5;
  background:
    radial-gradient(circle at 30% 40%, rgba(58, 119, 170, 0.15), transparent 50%),
    radial-gradient(circle at 70% 60%, rgba(201, 162, 39, 0.1), transparent 40%),
    linear-gradient(180deg, #12151c 0%, #0a0c10 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 12px;
}

.map-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

.map-zone {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  cursor: pointer;
  z-index: 2;
}

.zone-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin: 0 auto 4px;
  border: 2px solid rgba(255,255,255,0.3);
  transition: transform 0.15s;
}

.map-zone:active .zone-dot {
  transform: scale(1.2);
}

.zone-dot.safe { background: var(--safe); box-shadow: 0 0 12px rgba(68, 170, 153, 0.5); }
.zone-dot.danger { background: var(--danger); box-shadow: 0 0 12px rgba(204, 68, 68, 0.5); }
.zone-dot.mystery { background: var(--mystery); }
.zone-dot.forest { background: #5a8; }
.zone-dot.dungeon { background: #888; }
.zone-dot.hidden { background: #444; box-shadow: none; }

.zone-label {
  font-size: 9px;
  font-weight: 600;
  max-width: 70px;
  line-height: 1.2;
  color: var(--text-muted);
}

.map-zone.revealed .zone-label {
  color: var(--text);
}

.map-detail {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 60px;
}

.map-detail strong {
  color: var(--text);
  display: block;
  margin-bottom: 4px;
}

.fog-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

.fog-legend span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(13, 15, 20, 0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 2px;
  transition: color 0.15s;
}

.nav-btn .nav-icon {
  font-size: 20px;
  line-height: 1;
}

.nav-btn.active {
  color: var(--gold);
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--gold-dim);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  z-index: 150;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.install-banner span {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  min-height: auto;
}
