:root {
  --font-size: 14px;
  --font-size-sm: calc(var(--font-size) * 0.857);
  --font-size-xs: calc(var(--font-size) * 0.786);
  --font-size-lg: calc(var(--font-size) * 1.14);
  --bg: #0a0a0a;
  --bg2: #111;
  --bg3: #1a1a1a;
  --bg4: #222;
  --border: #2a2a2a;
  --border-light: #3a3a3a;
  --text: #e0e0e0;
  --text-dim: #888;
  --text-dark: #555;
  --accent: #c9a84c;
  --accent-hover: #dbb85c;
  --accent-dim: #8a7535;
  --success: #4caf50;
  --danger: #e53935;
  --warning: #ff9800;
  --info: #2196f3;
  --rarity-common: #b0b0b0;
  --rarity-uncommon: #4caf50;
  --rarity-rare: #2196f3;
  --rarity-epic: #9c27b0;
  --rarity-legendary: #ff9800;
  --region-hearthlands: #4a7c3f;
  --region-darkwood: #2d5a27;
  --region-stonebreak: #7a6b5a;
  --region-mistmarsh: #4a6a5a;
  --region-sunscorch: #c9a84c;
  --region-coral: #3a8a9a;
  --region-frosthold: #7ab8d4;
  --region-embercrag: #c44a2a;
  --region-wilderness: #8a2a2a;
}
html[data-font-size="compact"] { --font-size: 11px; }
html[data-font-size="small"]   { --font-size: 12px; }
html[data-font-size="large"]   { --font-size: 16px; }
html[data-font-size="xl"]      { --font-size: 19px; }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: var(--font-size);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ─── AUTH ─────────────────────────────────────────────── */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 100%);
}
.auth-box {
  background: var(--bg2); border: 1px solid var(--border);
  padding: 40px; border-radius: 8px; text-align: center; width: 360px;
}
.auth-box h1 { color: var(--accent); margin-bottom: 4px; font-size: 28px; }
.auth-subtitle { color: var(--text-dim); margin-bottom: 24px; font-size: var(--font-size-sm); }
#auth-form input {
  width: 100%; padding: 10px 12px; margin-bottom: 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: var(--font-size);
}
#auth-form input:focus { border-color: var(--accent); outline: none; }
.auth-buttons { display: flex; gap: 8px; margin-top: 8px; }
.auth-buttons button { flex: 1; padding: 10px; font-size: var(--font-size); }
.error-text { color: var(--danger); margin-top: 8px; font-size: var(--font-size-sm); min-height: 20px; }

/* ─── GAME LAYOUT ─────────────────────────────────────── */
#game-screen { display: flex; flex-direction: column; height: 100vh; }

#status-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 6px 16px; background: var(--bg2); border-bottom: 1px solid var(--border);
  font-size: var(--font-size-sm); flex-shrink: 0;
}
#player-name-display { color: var(--accent); font-weight: bold; }
#player-stats-display { color: var(--text); }
#player-zone-display { color: var(--text-dim); margin-left: auto; }
#online-count { color: var(--text-dark); font-size: var(--font-size-xs); }

#nav-bar {
  display: flex; gap: 2px; padding: 4px 8px; background: var(--bg3);
  border-bottom: 1px solid var(--border); flex-shrink: 0; align-items: center;
}
.nav-btn {
  padding: 5px 10px; font-size: var(--font-size-xs); background: transparent;
  border: 1px solid transparent; border-radius: 3px; cursor: pointer; color: var(--text-dim);
}
.nav-btn:hover { color: var(--text); border-color: var(--border); }
.nav-btn.active { color: var(--accent); border-color: var(--accent-dim); background: var(--bg); }
.nav-settings { margin-left: auto; }

/* XP Mini Bar */
#xp-mini-bar-wrap {
  height: 14px; background: var(--bg); border-bottom: 1px solid var(--border);
  position: relative; flex-shrink: 0;
}
#xp-mini-bar {
  height: 100%; background: var(--accent-dim); transition: width 0.5s;
  width: 0%;
}
#xp-mini-label {
  position: absolute; top: 0; left: 8px; font-size: 10px; line-height: 14px;
  color: #ddd; text-shadow: 0 0 3px #000, 0 0 6px #000;
}

/* Nav — full layout wraps */
#nav-bar[data-layout="full"] { flex-wrap: wrap; }

/* Nav dropdown groups */
.nav-dropdown { position: relative; display: inline-block; }
.nav-group-btn { color: var(--text-dim); }
.nav-group-btn:hover { color: var(--accent); }
.nav-dropdown-content {
  display: none; position: absolute; top: 100%; left: 0;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  min-width: 180px; z-index: 1000; box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  padding: 4px 0;
}
.nav-dropdown:hover .nav-dropdown-content { display: block; }
.nav-drop-item {
  padding: 7px 14px; cursor: pointer; font-size: var(--font-size-sm);
  color: var(--text); transition: background 0.1s;
}
.nav-drop-item:hover { background: var(--bg3); color: var(--accent); }

/* Nav sidebar layout */
#nav-sidebar {
  width: 170px; flex-shrink: 0; background: var(--bg2);
  border-right: 1px solid var(--border); overflow-y: auto;
  padding: 4px 0; font-size: var(--font-size-xs);
}
.has-nav-sidebar { display: flex; }
.nav-side-group {
  padding: 6px 12px 2px; color: var(--text-dark); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px;
}
.nav-side-item {
  padding: 5px 12px 5px 16px; cursor: pointer; color: var(--text-dim);
  transition: all 0.1s; border-left: 2px solid transparent;
}
.nav-side-item:hover { color: var(--text); background: var(--bg3); }
.nav-side-item.active {
  color: var(--accent); border-left-color: var(--accent); background: var(--bg);
}

#main-layout {
  display: flex; flex: 1; overflow: hidden;
}
#map-sidebar {
  width: 260px; flex-shrink: 0; border-right: 1px solid var(--border);
  background: var(--bg2); overflow: hidden;
}
#minimap { width: 100%; height: 100%; }

#content-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
#main-content {
  flex: 1; padding: 12px 16px; overflow-y: auto;
}
#event-log {
  height: 100px; border-top: 1px solid var(--border); background: var(--bg2);
  overflow-y: auto; padding: 6px 12px; font-size: var(--font-size-xs);
  flex-shrink: 0;
}
#event-log-entries .event-line { padding: 1px 0; }
.event-gather { color: var(--success); }
.event-combat { color: var(--danger); }
.event-loot { color: var(--accent); }
.event-chat { color: var(--info); }
.event-emote { color: #ce93d8; font-style: italic; }
.event-system { color: var(--text-dim); }
.event-quest { color: #ffab40; }
.event-travel { color: var(--text-dim); font-style: italic; }

#chat-bar {
  display: flex; gap: 4px; padding: 4px 12px;
  background: var(--bg3); border-top: 1px solid var(--border);
  font-size: var(--font-size-xs); flex-shrink: 0; align-items: center; flex-wrap: wrap;
}
#quickchat-buttons, #emote-buttons { display: flex; gap: 4px; }

/* ─── BUTTONS ─────────────────────────────────────────── */
button, .btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 3px; cursor: pointer;
  font-size: var(--font-size-sm); transition: all 0.15s;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button:active { background: var(--bg4); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); color: #000; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-small { padding: 3px 8px; font-size: var(--font-size-xs); }

.clickable { cursor: pointer; }
.clickable:hover { text-decoration: underline; }

/* ─── PANELS & CARDS ──────────────────────────────────── */
.panel {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px; padding: 12px; margin-bottom: 10px;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: bold; color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.item-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 3px;
  padding: 8px; cursor: pointer; transition: border-color 0.15s;
}
.item-card:hover { border-color: var(--accent); }
.item-card .item-name { font-weight: bold; font-size: var(--font-size-sm); }
.item-card .item-info { color: var(--text-dim); font-size: var(--font-size-xs); }

.rarity-common { color: var(--rarity-common); border-left: 3px solid var(--rarity-common); }
.rarity-uncommon { color: var(--rarity-uncommon); border-left: 3px solid var(--rarity-uncommon); }
.rarity-rare { color: var(--rarity-rare); border-left: 3px solid var(--rarity-rare); }
.rarity-epic { color: var(--rarity-epic); border-left: 3px solid var(--rarity-epic); }
.rarity-legendary { color: var(--rarity-legendary); border-left: 3px solid var(--rarity-legendary); }

/* ─── PROGRESS BARS ───────────────────────────────────── */
.progress-bar {
  height: 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 2px; overflow: hidden; position: relative;
}
.progress-fill {
  height: 100%; background: var(--accent-dim); transition: width 0.3s;
}
.progress-text {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  font-size: 10px; line-height: 14px; color: var(--text);
}

/* ─── TABLES ──────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--font-size-sm); }
.data-table th {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border);
  color: var(--text-dim); font-size: var(--font-size-xs);
}
.data-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--bg3); }

/* ─── MODALS ──────────────────────────────────────────── */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7); display: flex;
  align-items: center; justify-content: center; z-index: 1000;
}
.modal-content {
  background: var(--bg2); border: 1px solid var(--border);
  padding: 20px; border-radius: 6px; min-width: 300px; max-width: 500px;
}
.modal-content h3 { color: var(--accent); margin-bottom: 12px; }

/* ─── DROPDOWN ────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-content {
  display: none; position: absolute; bottom: 100%; left: 0;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  min-width: 180px; max-height: 200px; overflow-y: auto; z-index: 100;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.5);
}
.dropdown:hover .dropdown-content, .dropdown.open .dropdown-content { display: block; }
.dropdown-item {
  padding: 6px 12px; cursor: pointer; font-size: var(--font-size-sm);
  border-bottom: 1px solid var(--border);
}
.dropdown-item:hover { background: var(--bg3); color: var(--accent); }
.dropdown-item:last-child { border-bottom: none; }

/* ─── EQUIPMENT GRID ──────────────────────────────────── */
.equip-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  max-width: 350px;
}
.equip-slot {
  background: var(--bg); border: 1px solid var(--border); border-radius: 3px;
  padding: 8px 4px; text-align: center; font-size: var(--font-size-xs); min-height: 50px;
}
.equip-slot .slot-label { color: var(--text-dark); font-size: 10px; }
.equip-slot .slot-item { color: var(--text); font-size: var(--font-size-xs); margin-top: 2px; }

/* ─── SKILL BAR ───────────────────────────────────────── */
.skill-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.skill-name { width: 100px; font-size: var(--font-size-sm); }
.skill-level { width: 40px; text-align: right; color: var(--accent); font-weight: bold; }
.skill-bar-wrap { flex: 1; }

/* ─── MAP OVERRIDES ───────────────────────────────────── */
#map-sidebar { position: relative; z-index: 1; }
.leaflet-container { background: #0a0a0a !important; }

/* Zone SVG icons */
.zone-icon { background: none !important; border: none !important; }

@keyframes zonePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}
.zone-tooltip {
  background: var(--bg2) !important; color: var(--text) !important;
  border: 1px solid var(--accent) !important; font-size: var(--font-size-xs) !important;
  padding: 4px 8px !important; border-radius: 3px !important;
}
.zone-tooltip .zone-name { font-weight: bold; color: var(--accent); }
.zone-tooltip .zone-level { color: var(--text-dim); }

/* ─── VIEW INTROS ─────────────────────────────────────── */
.view-intro {
  color: var(--text-dim); font-size: var(--font-size-sm);
  font-style: italic; margin-bottom: 12px; line-height: 1.5;
}

/* ─── ZONE VIEW ───────────────────────────────────────── */
.zone-header { margin-bottom: 12px; }
.zone-header h2 { color: var(--accent); margin-bottom: 4px; }
.zone-header .zone-desc { color: var(--text-dim); font-size: var(--font-size-sm); }
.zone-header .zone-meta { display: flex; gap: 12px; margin-top: 6px; font-size: var(--font-size-xs); color: var(--text-dark); }

.resource-row, .monster-row, .travel-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; background: var(--bg3); border-radius: 3px; margin-bottom: 4px;
}
.resource-row .res-info, .monster-row .mon-info { flex: 1; }
.res-name, .mon-name { font-weight: bold; font-size: var(--font-size-sm); }
.res-detail, .mon-detail { color: var(--text-dim); font-size: var(--font-size-xs); }

/* NPC action panels in dialogue */
.npc-action-panel {
  margin: 8px 0; padding: 10px 12px; background: var(--bg3);
  border: 1px solid var(--accent-dim); border-radius: 4px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}

.pvp-badge { color: var(--danger); font-weight: bold; font-size: var(--font-size-xs); border: 1px solid var(--danger); padding: 1px 6px; border-radius: 3px; }

.mon-desc {
  color: var(--text-dim); font-size: var(--font-size-xs);
  font-style: italic; margin-top: 2px; max-width: 500px;
}
.mon-actions { display: flex; align-items: center; gap: 6px; }
.party-tag {
  display: inline-block; padding: 2px 6px; border-radius: 3px;
  font-size: var(--font-size-xs); font-weight: bold;
  background: rgba(100, 180, 255, 0.15); color: #6ab4ff;
  border: 1px solid rgba(100, 180, 255, 0.3); cursor: help;
}

/* ─── AMBIENT EVENT ───────────────────────────────────── */
.ambient-event {
  font-style: italic; color: var(--text-dim); font-size: var(--font-size-sm);
  padding: 8px 12px; margin-bottom: 12px;
  border-left: 3px solid var(--accent-dim); background: var(--bg2);
  border-radius: 0 4px 4px 0;
}

/* ─── FLOATING ACTION BAR ─────────────────────────────── */
.action-bar {
  display: flex; gap: 6px; margin-bottom: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.action-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 14px; border-radius: 4px; cursor: pointer;
  font-size: var(--font-size-sm); border: 1px solid var(--border);
  background: var(--bg3); color: var(--text); transition: all 0.15s;
}
.action-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.action-btn .action-icon { font-size: 16px; }
.action-btn .action-label { font-size: var(--font-size-xs); }
.action-gather { border-color: var(--success); }
.action-gather:hover { background: var(--success); color: #fff; }
.action-fight { border-color: var(--danger); }
.action-fight:hover { background: var(--danger); color: #fff; }
.action-social { border-color: var(--info); }
.action-social:hover { background: var(--info); color: #fff; }
.action-inv { border-color: var(--accent); }
.action-inv:hover { background: var(--accent); color: #000; }

/* ─── SETTING ROW ─────────────────────────────────────── */
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}

/* ─── COMBAT LOG ──────────────────────────────────────── */
.combat-result { margin-top: 12px; }
.combat-round {
  display: flex; gap: 16px; font-size: var(--font-size-xs);
  padding: 2px 0; color: var(--text-dim);
}
.hp-bar {
  height: 20px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 3px; overflow: hidden; position: relative; margin: 6px 0;
}
.hp-fill { height: 100%; transition: width 0.3s; }
.hp-fill.player { background: var(--success); }
.hp-fill.monster { background: var(--danger); }
.hp-text {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  font-size: 11px; line-height: 20px; color: #fff; text-shadow: 0 0 3px #000;
}

.loot-item { color: var(--accent); }
.victory { color: var(--success); font-weight: bold; }
.defeat { color: var(--danger); font-weight: bold; }

.combat-round-detail {
  margin-bottom: 6px; padding: 4px 8px; background: var(--bg);
  border-radius: 3px; border-left: 2px solid var(--border);
}
.round-header { color: var(--text-dim); font-size: var(--font-size-xs); font-weight: bold; }
.round-action { font-size: var(--font-size-xs); padding: 1px 0; }
.player-action { color: var(--success); }
.enemy-action { color: var(--danger); }
.round-hp { display: flex; gap: 16px; font-size: var(--font-size-xs); margin-top: 2px; }

/* Staged combat reveal */
.stage-hidden { opacity: 0; max-height: 0; overflow: hidden; transition: all 0.4s ease; }
.stage-reveal { opacity: 1; max-height: 500px; transition: all 0.4s ease; }

/* ─── MOBILE RESPONSIVE ───────────────────────────────── */
@media (max-width: 900px) {
  #main-layout { flex-direction: column; }
  #map-sidebar { width: 100%; height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  #nav-bar { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .nav-btn { white-space: nowrap; flex-shrink: 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .equip-grid { grid-template-columns: repeat(4, 1fr); }
  .action-bar { flex-wrap: wrap; }
  #event-log { height: 80px; }
  .auth-box { width: 90%; max-width: 360px; padding: 24px; }
}

@media (max-width: 600px) {
  #status-bar { flex-wrap: wrap; font-size: var(--font-size-xs); gap: 8px; }
  .grid-3 { grid-template-columns: 1fr; }
  .equip-grid { grid-template-columns: repeat(3, 1fr); }
  #map-sidebar { height: 160px; }
  .panel { padding: 8px; }
  .market-search { flex-direction: column; }
  .resource-row, .monster-row, .travel-row { flex-direction: column; gap: 4px; align-items: flex-start; }
  .resource-row button, .monster-row button, .travel-row button { align-self: flex-end; }
  .combat-round-detail { font-size: 11px; }
  .grid-dungeon-layout { flex-direction: column; }
  .grid-dungeon-layout .grid-dungeon-map { max-width: 100%; }
  .grid-tile { min-width: 28px; min-height: 28px; font-size: 14px; }
}

/* ─── GRID DUNGEON ───────────────────────────────────── */
.grid-dungeon-container { max-width: 100%; }
.grid-dungeon-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.grid-dungeon-layout { display: flex; gap: 16px; align-items: stretch; }
.grid-dungeon-layout .grid-dungeon-map { flex: 0 0 auto; width: min(55vw, 550px); aspect-ratio: 1; }
.grid-dungeon-sidebar { flex: 1; min-width: 200px; display: flex; flex-direction: column; }
.grid-dungeon-map {
  display: grid; gap: 0px;
  border: 3px solid #333; border-radius: 2px;
  padding: 0; background: #050505;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}
.grid-tile {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 18px; position: relative; overflow: hidden;
  min-width: 0; min-height: 0;
  transition: opacity 0.3s;
  font-family: 'Courier New', monospace;
  image-rendering: pixelated;
}
.tile-fog { background: #050505 !important; }
.tile-wall {
  background: #181818 !important;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 3px, rgba(255,255,255,0.02) 3px, rgba(255,255,255,0.02) 4px) !important;
}
.tile-stone {
  background-image: radial-gradient(circle at 30% 40%, rgba(255,255,255,0.03) 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.02) 1px, transparent 1px);
}
.tile-danger { box-shadow: inset 0 0 8px rgba(180,40,40,0.3); }
.tile-boss-tile { box-shadow: inset 0 0 12px rgba(180,40,40,0.5); }
.tile-clickable { cursor: pointer; }
.tile-clickable:hover { box-shadow: inset 0 0 10px rgba(201,168,76,0.4); outline: 1px solid rgba(201,168,76,0.5); z-index: 1; }
.tile-glyph { font-size: 16px; opacity: 0.6; }
.tile-svg { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2; }
.tile-svg svg { width: 65%; height: 65%; filter: drop-shadow(0 0 2px rgba(0,0,0,0.8)); }
.tile-sprite {
  image-rendering: pixelated; position: relative; z-index: 2;
  margin: auto;
}
.tile-boss-sprite { filter: drop-shadow(0 0 4px rgba(255,50,50,0.6)); }
.tile-blood-sprite {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  image-rendering: pixelated; z-index: 1; opacity: 0.8;
}
.tile-entity {
  font-size: 22px; font-weight: bold; z-index: 2;
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 4px currentColor;
}
.tile-entity-me {
  color: #e8c84a; font-size: 24px;
  text-shadow: 0 0 8px rgba(232,200,74,0.6), 0 0 16px rgba(232,200,74,0.3);
  animation: playerPulse 2s ease-in-out infinite;
}
.tile-entity-ally { color: #6ab4ff; text-shadow: 0 0 6px rgba(106,180,255,0.4); }

@keyframes playerPulse {
  0%, 100% { text-shadow: 0 0 8px rgba(232,200,74,0.6); }
  50% { text-shadow: 0 0 14px rgba(232,200,74,0.9), 0 0 24px rgba(232,200,74,0.3); }
}

.grid-controls { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.grid-dpad { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grid-dpad-row { display: flex; gap: 2px; }
.grid-dir {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  background: #1a1a1a; border: 1px solid #333; border-radius: 3px;
  color: var(--text-dim); font-size: 16px; cursor: pointer; transition: all 0.15s;
}
.grid-dir:hover { background: #2a2520; color: var(--accent); border-color: var(--accent); }
.grid-dir:active { transform: scale(0.92); background: var(--accent); color: #000; }
.grid-wait { font-size: 20px; color: var(--text-dark); }
.grid-legend {
  display: flex; flex-direction: column; gap: 3px;
  font-size: var(--font-size-xs); color: var(--text-dim);
  font-family: 'Courier New', monospace;
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-item svg { flex-shrink: 0; }

/* Blood splatter */
.tile-blood { position: relative; }
.tile-blood::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 40% 60%, rgba(120,20,20,0.4) 0%, transparent 70%),
    radial-gradient(ellipse at 70% 30%, rgba(100,10,10,0.3) 0%, transparent 50%);
  pointer-events: none;
}

/* Cracked floor variation */
.tile-cracked::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.03) 41%, transparent 42%),
    linear-gradient(225deg, transparent 60%, rgba(255,255,255,0.02) 61%, transparent 62%);
  pointer-events: none;
}

/* Water tile */
.tile-water {
  background: #0a1525 !important;
  animation: waterShimmer 3s ease-in-out infinite;
}
@keyframes waterShimmer {
  0%, 100% { background-color: #0a1525; }
  50% { background-color: #0d1a2d; }
}

/* Lava tile */
.tile-lava {
  background: #1a0800 !important;
  animation: lavaGlow 2s ease-in-out infinite;
}
@keyframes lavaGlow {
  0%, 100% { box-shadow: inset 0 0 8px rgba(255,60,0,0.3); }
  50% { box-shadow: inset 0 0 14px rgba(255,80,0,0.5); }
}

/* Torch flicker on explored tiles near player */
.tile-stone { animation: torchFlicker 4s ease-in-out infinite; }
@keyframes torchFlicker {
  0%, 100% { filter: brightness(1); }
  25% { filter: brightness(1.04); }
  50% { filter: brightness(0.96); }
  75% { filter: brightness(1.02); }
}

/* Targeting overlay */
.tile-targetable {
  cursor: crosshair !important;
  box-shadow: inset 0 0 12px rgba(255,100,100,0.5), 0 0 4px rgba(255,50,50,0.4) !important;
  animation: targetPulse 0.8s ease-in-out infinite !important;
}
@keyframes targetPulse {
  0%, 100% { box-shadow: inset 0 0 12px rgba(255,100,100,0.5); }
  50% { box-shadow: inset 0 0 18px rgba(255,100,100,0.8), 0 0 6px rgba(255,50,50,0.5); }
}

/* Skill bar */
.grid-skillbar { margin-bottom: 12px; }
.grid-skill-btn {
  padding: 4px 10px; font-size: var(--font-size-xs);
  background: #1a1a1a; border: 1px solid #444; border-radius: 3px;
  color: var(--text-dim); cursor: pointer; transition: all 0.15s;
  font-family: 'Courier New', monospace;
}
.grid-skill-btn:hover { border-color: var(--accent); color: var(--accent); }
.grid-skill-active { border-color: #ff5555; color: #ff5555; background: rgba(255,50,50,0.1); }

/* ─── SCROLLBAR ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ─── MARKET ──────────────────────────────────────────── */
.market-search {
  display: flex; gap: 8px; margin-bottom: 12px;
}
.market-search input {
  flex: 1; padding: 6px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 3px;
  color: var(--text); font-size: var(--font-size-sm);
}
.market-search input:focus { border-color: var(--accent); outline: none; }

/* ─── FORM INPUTS ─────────────────────────────────────── */
input[type="number"], input[type="text"], select {
  padding: 5px 8px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 3px; color: var(--text); font-size: var(--font-size-sm);
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
select { cursor: pointer; }

/* ─── GATHERING MINIGAMES ─────────────────────────────── */
.minigame-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.85); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.minigame-container {
  background: var(--bg2); border: 2px solid var(--accent); border-radius: 8px;
  padding: 24px 32px; text-align: center; max-width: 400px; width: 90%;
}
.minigame-title {
  font-size: var(--font-size-lg); color: var(--accent); font-weight: bold; margin-bottom: 8px;
}
.minigame-hint {
  font-size: var(--font-size-sm); color: var(--text-dim); margin-bottom: 16px;
}
.minigame-btn {
  margin-top: 16px; padding: 10px 32px; font-size: var(--font-size); cursor: pointer;
  user-select: none; -webkit-user-select: none;
}

/* Swing meter */
.swing-track {
  position: relative; height: 32px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; overflow: hidden; margin: 12px 0;
}
.swing-zone { position: absolute; top: 0; height: 100%; }
.swing-poor { background: var(--danger); opacity: 0.3; }
.swing-good { background: var(--success); opacity: 0.35; }
.swing-good-r { background: var(--danger); opacity: 0.3; }
.swing-perfect { background: var(--rarity-legendary); opacity: 0.4; }
.swing-marker {
  position: absolute; top: 0; width: 4px; height: 100%; background: #fff;
  transition: none; border-radius: 2px;
}
.swing-hit-perfect { background: var(--rarity-legendary) !important; box-shadow: 0 0 12px var(--rarity-legendary); }
.swing-hit-good { background: var(--success) !important; box-shadow: 0 0 8px var(--success); }
.swing-hit-miss { background: var(--danger) !important; }

/* Tension meter */
.tension-bars { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.tension-bar-wrap { display: flex; align-items: center; gap: 8px; }
.tension-label { font-size: var(--font-size-xs); color: var(--text-dim); width: 60px; text-align: right; }
.tension-bar {
  flex: 1; height: 20px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 3px; overflow: hidden;
}
.tension-fill { height: 100%; width: 0; background: var(--success); transition: width 0.05s, background 0.2s; }
.progress-fill { height: 100%; width: 0; background: var(--info); transition: width 0.05s; }
.tension-fish {
  font-size: 32px; margin: 8px 0; transition: transform 0.1s;
}

/* Rhythm chops */
.rhythm-area {
  display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 12px 0;
}
.rhythm-ring {
  width: 80px; height: 80px; border: 4px solid var(--border); border-radius: 50%;
  transition: all 0.15s;
}
.rhythm-pulse {
  border-color: var(--accent); box-shadow: 0 0 20px var(--accent);
  transform: scale(1.15);
}
.rhythm-hit {
  border-color: var(--success); box-shadow: 0 0 16px var(--success);
}
.rhythm-combo {
  font-size: var(--font-size-lg); font-weight: bold; min-height: 24px;
}
.rhythm-progress { font-size: var(--font-size-sm); color: var(--text-dim); }

/* Precision pick */
.precision-area {
  position: relative; width: 260px; height: 260px; margin: 12px auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  cursor: crosshair; overflow: hidden;
}
.precision-target {
  position: absolute; font-size: 28px; user-select: none; pointer-events: none;
  transition: none;
}
.precision-hit { animation: precisionFlash 0.2s; }
@keyframes precisionFlash {
  0% { transform: scale(1.5); } 100% { transform: scale(1); }
}
.precision-progress { font-size: var(--font-size-sm); color: var(--text-dim); margin-top: 8px; }

/* Defeat flash animation for grid dungeon */
@keyframes defeatFadeOut {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95); }
}
