
/* Ensure elements using the HTML hidden attribute never remain visible. */
[hidden] {
  display: none !important;
}
:root {
  --bg: #0d0d0c;
  --panel: #151513;
  --panel-2: #1b1a17;
  --panel-3: #23211d;
  --line: rgba(224, 198, 139, 0.18);
  --line-strong: rgba(224, 198, 139, 0.34);
  --gold: #d8b66d;
  --gold-bright: #f0d99f;
  --cream: #efe7d5;
  --muted: #a49d90;
  --red: #8f2b2e;
  --red-bright: #c75252;
  --green: #5e8a63;
  --blue: #5b7894;
  --orange: #b6783d;
  --shadow: 0 18px 45px rgba(0,0,0,.34);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(133, 83, 40, .14), transparent 33%),
    radial-gradient(circle at 90% 20%, rgba(91, 45, 48, .12), transparent 28%),
    var(--bg);
  color: var(--cream);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.app-shell { min-height: 100vh; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: rgba(13,13,12,.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; gap: 16px; align-items: center; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--line-strong);
  color: var(--gold-bright);
  background: linear-gradient(145deg, #272118, #12110f);
  font-size: 24px;
  box-shadow: inset 0 0 20px rgba(216,182,109,.08);
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .18em;
}
h1,h2,h3,p { margin-top: 0; }
h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: .01em;
}
h1 { margin-bottom: 2px; font-size: clamp(24px, 4vw, 38px); }
.tagline { margin: 0; color: var(--muted); font-family: Georgia, serif; font-style: italic; }
.header-actions, .button-row, .map-toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.primary-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: #11110f;
  position: sticky;
  top: 101px;
  z-index: 25;
}
.nav-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 11px 15px;
  border-radius: 10px;
  white-space: nowrap;
  font-weight: 700;
}
.nav-tab:hover, .nav-tab.active {
  color: var(--cream);
  background: rgba(216,182,109,.11);
}

main { padding: 24px clamp(16px, 3vw, 42px) 48px; }
.view { display: none; }
.view.active { display: block; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat-card {
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(32,30,26,.92), rgba(20,20,18,.96));
  box-shadow: var(--shadow);
}
.stat-card span, .stat-card small { color: var(--muted); }
.stat-card strong { display: block; font-family: Georgia, serif; font-size: 28px; margin: 5px 0; color: var(--gold-bright); }
.stat-card.danger strong { color: #e58b8b; }

.panel {
  background: linear-gradient(145deg, rgba(25,24,21,.97), rgba(18,18,16,.97));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.map-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: stretch;
}
.map-tools, .territory-panel { padding: 18px; }
.map-panel { overflow: hidden; min-width: 0; }
.panel-heading, .map-toolbar, .section-title-row, .territory-title-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.panel-heading h2, .map-toolbar h2, .territory-title-row h2 { margin-bottom: 0; }
.field { display: grid; gap: 7px; margin: 16px 0; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0f0f0d;
  color: var(--cream);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(216,182,109,.10); }
textarea { min-height: 90px; resize: vertical; }

.ghost-button, .staff-button, .primary-button, .danger-button, .staff-only-button, .icon-button {
  border-radius: 10px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  color: var(--cream);
  background: #1c1b18;
  font-weight: 800;
}
.staff-button, .primary-button, .staff-only-button {
  background: linear-gradient(135deg, #8f6b34, #c09a54);
  color: #100e0a;
  border-color: #d5b56e;
}
.danger-button { background: #3d1718; border-color: rgba(199,82,82,.48); color: #f4c5c5; }
.ghost-button:hover, .icon-button:hover { border-color: var(--gold); }
.full { width: 100%; }
.icon-button { min-width: 40px; padding-inline: 11px; }

.map-toolbar { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.map-toolbar h2 { font-size: 20px; }
.map-stage {
  position: relative;
  min-height: 650px;
  overflow: hidden;
  background:
    radial-gradient(circle at 55% 30%, rgba(95,117,124,.18), transparent 35%),
    #101a1e;
  touch-action: none;
}
#realmMap { width: 100%; height: 650px; display: block; user-select: none; }
.sea { fill: #101b20; }
.territory {
  stroke: rgba(239,231,213,.34);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  transition: filter .16s ease, opacity .16s ease, stroke-width .16s ease;
  cursor: pointer;
}
.territory:hover, .territory.selected {
  stroke: #f4dfac;
  stroke-width: 4;
  filter: brightness(1.22);
}
.territory.dimmed { opacity: .18; }
.map-label {
  fill: #f2ead9;
  font-family: Georgia, serif;
  font-weight: 700;
  font-size: 13px;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0,0,0,.72);
  stroke-width: 3px;
}
.marker {
  cursor: pointer;
  stroke: rgba(0,0,0,.55);
  stroke-width: 1.5;
}
.marker.army { fill: #c95252; }
.marker.settlement { fill: #e0c075; }
.marker.port { fill: #6d9caf; }
.marker.castle { fill: #d9d4c9; }
.marker-label { fill: white; font-size: 10px; font-weight: 800; text-anchor: middle; pointer-events: none; }
.map-compass circle { fill: rgba(10,10,9,.72); stroke: rgba(216,182,109,.5); }
.map-compass path { fill: var(--gold); }
.map-compass text { fill: var(--gold-bright); text-anchor: middle; font-weight: 900; font-size: 12px; }

.map-tooltip {
  position: absolute;
  z-index: 10;
  background: rgba(8,8,7,.96);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--cream);
  pointer-events: none;
  box-shadow: var(--shadow);
  max-width: 230px;
  font-size: 12px;
}
.map-tooltip strong { display: block; color: var(--gold-bright); margin-bottom: 3px; }

.legend { display: grid; gap: 8px; margin: 16px 0; }
.legend-item { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); }
.map-toggle-row { display: grid; gap: 10px; margin: 20px 0; font-size: 13px; color: var(--muted); }
.map-toggle-row label { display: flex; align-items: center; gap: 8px; }
.map-toggle-row input { width: auto; }
.tool-note {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(216,182,109,.06);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.empty-state { min-height: 520px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state h3 { color: var(--cream); margin-bottom: 6px; }
.empty-icon { font-size: 46px; color: var(--gold); margin-bottom: 10px; }

.status-pill {
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 900;
  background: rgba(94,138,99,.18);
  color: #9fd1a5;
  border: 1px solid rgba(94,138,99,.35);
}
.status-pill.claimed { background: rgba(216,182,109,.14); color: var(--gold-bright); border-color: var(--line-strong); }
.status-pill.war { background: rgba(199,82,82,.16); color: #ec9b9b; border-color: rgba(199,82,82,.38); }

.house-banner {
  display: flex; gap: 12px; align-items: center;
  margin: 16px 0; padding: 13px;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(255,255,255,.02);
}
.house-sigil {
  width: 50px; height: 50px; border-radius: 12px;
  display: grid; place-items: center;
  font-family: Georgia, serif; font-size: 23px; font-weight: 900;
  background: #28231c; color: var(--gold-bright); border: 1px solid var(--line);
}
.house-banner small, .house-banner span { display: block; color: var(--muted); font-size: 11px; }
.house-banner strong { display: block; margin: 2px 0 3px; }

.detail-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-stats div {
  background: #10100e; border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
.detail-stats span { display: block; color: var(--muted); font-size: 11px; }
.detail-stats strong { display: block; margin-top: 4px; color: var(--gold-bright); }
.detail-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.detail-section:last-of-type { border-bottom: 0; }
.detail-section h3 { margin-bottom: 10px; font-size: 17px; }
.detail-section p { color: var(--muted); line-height: 1.55; font-size: 13px; }
.stack-list { display: grid; gap: 8px; }
.stack-item {
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.018);
}
.stack-item strong { display: block; font-size: 13px; }
.stack-item span { color: var(--muted); font-size: 11px; }
.war-summary {
  padding: 11px; border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted); font-size: 12px; line-height: 1.55;
}

.section-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  margin: 8px 0 22px;
}
.section-header h2 { font-size: clamp(28px, 4vw, 42px); margin-bottom: 8px; }
.section-header p { max-width: 800px; color: var(--muted); line-height: 1.6; }
.filters-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 18px; }

.house-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
.house-card {
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, #1b1a17, #121210);
  box-shadow: var(--shadow);
}
.house-card-accent { height: 7px; }
.house-card-body { padding: 18px; }
.house-card-top { display: flex; gap: 12px; align-items: center; margin-bottom: 13px; }
.house-card h3 { margin-bottom: 3px; }
.house-card p { color: var(--muted); line-height: 1.5; font-size: 13px; }
.house-card-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 13px 0; }
.house-card-stats div { padding: 9px; border: 1px solid var(--line); border-radius: 9px; }
.house-card-stats span { display:block; color:var(--muted); font-size:10px; }
.house-card-stats strong { display:block; margin-top:4px; font-size:13px; }
.tag-row { display:flex; gap:6px; flex-wrap:wrap; }
.tag { padding: 5px 8px; border-radius: 999px; background: rgba(216,182,109,.08); border:1px solid var(--line); color:var(--muted); font-size:10px; font-weight:800; }

.economy-layout { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(280px,.7fr); gap: 14px; }
.economy-layout .panel { padding: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--gold); font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }
td { color: var(--muted); }
td strong { color: var(--cream); }

.catalogue { display: grid; gap: 9px; }
.catalogue-item {
  padding: 12px; border-radius: 11px; border: 1px solid var(--line); background: rgba(255,255,255,.02);
}
.catalogue-item-top { display:flex; justify-content:space-between; gap:10px; }
.catalogue-item strong { color: var(--cream); }
.catalogue-item p { margin: 7px 0 0; font-size: 12px; line-height:1.45; color:var(--muted); }
.catalogue-price { color: var(--gold-bright); white-space:nowrap; }

.turn-panel { margin-top:14px; padding:20px; display:flex; align-items:center; justify-content:space-between; gap:16px; }
.turn-panel h3 { margin-bottom:6px; }
.turn-panel p { margin:0; color:var(--muted); }

.war-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap:14px; }
.war-card { padding:18px; }
.war-card-header { display:flex; justify-content:space-between; gap:12px; }
.war-card h3 { margin-bottom:5px; }
.war-card p { color:var(--muted); line-height:1.5; font-size:13px; }
.war-sides { display:grid; grid-template-columns:1fr auto 1fr; gap:10px; align-items:center; margin:14px 0; }
.war-side { padding:12px; border:1px solid var(--line); border-radius:10px; text-align:center; }
.war-side strong, .war-side span { display:block; }
.war-side span { color:var(--muted); font-size:11px; margin-top:4px; }
.vs { color:var(--red-bright); font-weight:900; }
.progress-bar { height:9px; background:#0d0d0b; border:1px solid var(--line); border-radius:999px; overflow:hidden; }
.progress-fill { height:100%; background:linear-gradient(90deg,#8f2b2e,#d8b66d); }

.locked-admin { min-height: 560px; display:grid; place-content:center; text-align:center; }
.locked-admin p { color:var(--muted); max-width:550px; line-height:1.6; }
.lock-icon { font-size:58px; color:var(--gold); }
.admin-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.admin-card { padding:20px; }
.admin-card p { color:var(--muted); line-height:1.55; }
.audit-panel { margin-top:14px; padding:18px; }
.audit-list { display:grid; gap:8px; }
.audit-item { display:flex; justify-content:space-between; gap:12px; padding:10px; border-bottom:1px solid var(--line); color:var(--muted); font-size:12px; }
.audit-item strong { color:var(--cream); }
.file-label input { display:none; }

.modal-backdrop {
  position:fixed; inset:0; z-index:100;
  background:rgba(0,0,0,.78);
  display:grid; place-items:center;
  padding:16px;
  backdrop-filter:blur(8px);
}
.modal {
  width:min(760px,100%);
  max-height:90vh;
  overflow:auto;
  border-radius:18px;
  background:#151513;
  border:1px solid var(--line-strong);
  box-shadow:0 30px 90px rgba(0,0,0,.66);
}
.modal-header {
  display:flex; align-items:flex-start; justify-content:space-between; gap:15px;
  padding:20px; border-bottom:1px solid var(--line);
  position:sticky; top:0; background:#151513; z-index:2;
}
.modal-header h2 { margin-bottom:0; }
#modalBody { padding:20px; }
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:13px; }
.form-grid .full-span { grid-column:1/-1; }
.form-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:20px; }
.form-section { margin:20px 0 10px; padding-top:18px; border-top:1px solid var(--line); }
.inline-list { display:grid; gap:8px; }
.inline-row { display:grid; grid-template-columns:1.4fr .8fr auto; gap:8px; align-items:center; }
.check-row { display:flex; align-items:center; gap:8px; color:var(--muted); }
.check-row input { width:auto; }

.toast {
  position:fixed; right:18px; bottom:18px; z-index:120;
  background:#242019; color:var(--cream);
  border:1px solid var(--line-strong); border-radius:12px;
  padding:12px 15px; box-shadow:var(--shadow);
  max-width:min(400px,calc(100vw - 36px));
}

footer {
  display:flex; justify-content:space-between; gap:20px; flex-wrap:wrap;
  padding:22px clamp(18px,4vw,54px);
  border-top:1px solid var(--line);
  color:var(--muted); font-size:12px;
}

@media (max-width: 1180px) {
  .map-layout { grid-template-columns: 220px minmax(0,1fr); }
  .territory-panel { grid-column: 1/-1; }
  .empty-state { min-height: 180px; }
}
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns:repeat(2,1fr); }
  .map-layout { grid-template-columns:1fr; }
  .map-tools { order:2; }
  .map-panel { order:1; }
  .territory-panel { order:3; }
  .house-grid { grid-template-columns:repeat(2,1fr); }
  .economy-layout { grid-template-columns:1fr; }
  .war-grid { grid-template-columns:1fr; }
  .primary-nav { top: 95px; }
}
@media (max-width: 640px) {
  .topbar { align-items:flex-start; position:relative; }
  .brand-mark { display:none; }
  .header-actions { width:100%; }
  .header-actions button { flex:1; }
  .topbar { flex-direction:column; }
  .primary-nav { top:0; }
  main { padding-inline:12px; }
  .dashboard-grid { grid-template-columns:1fr 1fr; gap:9px; }
  .stat-card { padding:14px; }
  .stat-card strong { font-size:23px; }
  .map-stage, #realmMap { min-height:520px; height:520px; }
  .house-grid { grid-template-columns:1fr; }
  .filters-row { grid-template-columns:1fr; }
  .admin-grid { grid-template-columns:1fr; }
  .section-header, .turn-panel { flex-direction:column; align-items:stretch; }
  .form-grid { grid-template-columns:1fr; }
  .form-grid .full-span { grid-column:auto; }
  .inline-row { grid-template-columns:1fr; }
}
