/* Système commun d'interface médiévale — Royaumes d'Aether (Lot UI)
 * Maquette HTML/CSS éditable locale : 100% fenêtre sans scroll global, panneaux internes défilants.
 * États hover / active / disabled / focus-visible gérés exclusivement par CSS.
 */
:root {
  --bg-parchment: #eae0ca;
  --bg-parchment-soft: #f2ead8;
  --bg-parchment-deep: #ddd0b4;
  --bg-wood-dark: #35271c;
  --bg-wood-mid: #4b3727;
  --bg-stone-bar: #bfb8a6;
  --bg-metal: #5d676d;
  --ink-primary: #241c14;
  --ink-secondary: #534434;
  --ink-muted: #74634f;
  --ink-on-dark: #f4ebd7;
  --ink-gold: #e5c16c;
  --border-oak: #5a422e;
  --border-iron: #4c555a;
  --border-hairline: rgba(58, 42, 26, 0.24);
  --accent-gold: #b8892e;
  --accent-emerald: #3a6b48;
  --accent-crimson: #9e3d32;
  --accent-azure: #38657f;
  --accent-amber: #b37424;
  --focus-ring: #245c7a;
  --radius-sm: 4px;
  --radius-md: 6px;
  --scroll-track: #ddd0b4;
  --scroll-edge: #c5b38e;
  --scroll-thumb: #85603a;
  --scroll-highlight: #b3925f;
  --scroll-hover: #c8a268;
}

*, *::before, *::after { box-sizing: border-box; }

/* Défilement intégré au parchemin ; bronze patiné sur les panneaux en bois. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

.hud-nav {
  --scroll-track: #2b2017;
  --scroll-edge: #493524;
  --scroll-thumb: #927044;
  --scroll-highlight: #ba965e;
  --scroll-hover: #d0ac70;
}

.hud-nav, .panel-scroll {
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

/* Chrome : conserver les reliefs du curseur plutôt que le rendu système plat. */
@supports selector(::-webkit-scrollbar) {
  * { scrollbar-width: auto; scrollbar-color: auto; }
  *::-webkit-scrollbar { width: 10px; height: 10px; }
  *::-webkit-scrollbar-track {
    background: var(--scroll-track);
    border: 1px solid var(--scroll-edge);
    border-radius: 3px;
    box-shadow: inset 0 1px 3px rgb(36 28 20 / 16%);
  }
  *::-webkit-scrollbar-thumb {
    min-height: 32px;
    min-width: 32px;
    border: 2px solid var(--scroll-track);
    border-radius: 4px;
    background: linear-gradient(90deg, var(--scroll-highlight), var(--scroll-thumb));
    background-clip: padding-box;
    box-shadow: inset 0 0 0 1px rgb(65 43 23 / 28%);
  }
  *::-webkit-scrollbar-thumb:horizontal {
    background-image: linear-gradient(180deg, var(--scroll-highlight), var(--scroll-thumb));
  }
  *::-webkit-scrollbar-thumb:hover {
    background-color: var(--scroll-hover);
    background-image: none;
  }
  *::-webkit-scrollbar-thumb:active {
    background-color: var(--scroll-thumb);
    background-image: none;
  }
  *::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
  *::-webkit-scrollbar-corner { background: var(--scroll-track); }
  .res-ribbon::-webkit-scrollbar { display: none; width: 0; height: 0; }
}

@media (forced-colors: active) {
  * { scrollbar-color: auto; scrollbar-width: auto; }
  *::-webkit-scrollbar-track, *::-webkit-scrollbar-corner {
    background: Canvas; border-color: CanvasText; box-shadow: none;
  }
  *::-webkit-scrollbar-thumb,
  *::-webkit-scrollbar-thumb:hover,
  *::-webkit-scrollbar-thumb:active {
    background: ButtonText; border-color: Canvas; box-shadow: none;
  }
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: 14px;
  line-height: 1.42;
  color: var(--ink-primary);
  background-color: #261d15;
}

.app-shell {
  display: grid;
  grid-template-rows: 54px 1fr;
  grid-template-columns: 214px 1fr;
  grid-template-areas:
    "topbar topbar"
    "nav stage";
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Barre supérieure d'empire */
.hud-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  color: var(--ink-on-dark);
  background:
    linear-gradient(180deg, rgba(40, 29, 20, 0.86), rgba(31, 22, 15, 0.92)),
    url('/assets/art/ui-wood.webp') center/256px repeat;
  border-bottom: 2px solid var(--border-iron);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.city-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.city-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: rgba(238, 228, 205, 0.12);
  border: 1px solid rgba(229, 193, 108, 0.45);
  border-radius: var(--radius-sm);
  color: var(--ink-on-dark);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.mockup-tag {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(229, 193, 108, 0.18);
  border: 1px solid rgba(229, 193, 108, 0.45);
  color: var(--ink-gold);
  white-space: nowrap;
}

.res-ribbon {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.res-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  background: rgba(20, 14, 9, 0.55);
  border: 1px solid rgba(188, 166, 126, 0.3);
  border-radius: var(--radius-sm);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  color: var(--ink-on-dark);
  white-space: nowrap;
}

.res-chip img, .icon-sm { width: 16px; height: 16px; vertical-align: -3px; flex-shrink: 0; }
.icon-md { width: 20px; height: 20px; vertical-align: -4px; flex-shrink: 0; }
.icon-lg { width: 26px; height: 26px; flex-shrink: 0; }

.res-rate { color: #b7d39c; font-size: 11px; }
.res-warn { color: #f0b665; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Rail de navigation latéral défilant */
.hud-nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 8px 14px;
  color: var(--ink-on-dark);
  background:
    linear-gradient(180deg, rgba(47, 34, 24, 0.92), rgba(34, 25, 17, 0.96)),
    url('/assets/art/ui-wood.webp') center/256px repeat;
  border-right: 2px solid var(--border-iron);
}

.nav-section-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #cbb996;
  margin: 8px 8px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 9px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--ink-on-dark);
  text-decoration: none;
  font-size: 13px;
  border: 1px solid transparent;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.nav-link img {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.45));
}

.nav-link:hover {
  background: rgba(238, 226, 198, 0.13);
  border-color: rgba(229, 193, 108, 0.35);
}

.nav-link[aria-current="page"] {
  background: linear-gradient(90deg, rgba(229, 193, 108, 0.28), rgba(229, 193, 108, 0.1));
  border-color: var(--ink-gold);
  color: #fff8e6;
  font-weight: 700;
}

.nav-link:focus-visible, .btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Scène centrale sans scroll global */
.hud-stage {
  grid-area: stage;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: 12px;
  display: grid;
  gap: 12px;
  background:
    radial-gradient(circle at 30% 25%, rgba(65, 82, 62, 0.25), rgba(28, 23, 18, 0.85)),
    url('/assets/art/ui-stone.webp') center/320px repeat;
}

/* Layouts de scène */
.stage-split-map { grid-template-columns: 1fr 390px; }
.stage-split-equal { grid-template-columns: 1fr 1fr; }
.stage-sidebar-main { grid-template-columns: 330px 1fr; }
.stage-three-col { grid-template-columns: 300px 1fr 340px; }
.stage-single { grid-template-columns: 1fr; }

/* Panneau 9-tranches parchemin */
.ui-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background-color: var(--bg-parchment);
  background-image: url('/assets/art/ui-parchment.webp');
  background-size: 512px 512px;
  border: 14px solid var(--border-oak);
  border-image-source: url('/assets/art/panel-frame.webp');
  border-image-slice: 96 fill;
  border-image-width: 18px;
  border-image-repeat: stretch;
  border-radius: var(--radius-md);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.38);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border-hairline);
  background: linear-gradient(180deg, rgba(255, 250, 238, 0.55), rgba(215, 198, 164, 0.35));
  flex-shrink: 0;
}

.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-subtitle {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  color: var(--ink-secondary);
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
}

.panel-footer {
  padding: 9px 14px;
  border-top: 1px solid var(--border-hairline);
  background: rgba(212, 196, 164, 0.38);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

/* Infobulle 9-tranches avec repli net sur parchemin + fer patiné */
.ui-tooltip {
  background:
    linear-gradient(180deg, rgba(248, 241, 226, 0.92), rgba(232, 220, 194, 0.94)),
    url('/assets/art/ui-parchment.webp') center/256px repeat;
  border: 2px solid var(--border-iron);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 12.5px;
  color: var(--ink-primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3), inset 0 0 0 1px rgba(184, 137, 46, 0.35);
}

/* Bandeau de titre vierge réutilisable */
.banner-plaque {
  background:
    linear-gradient(180deg, rgba(242, 231, 206, 0.88), rgba(220, 204, 170, 0.92)),
    url('/assets/art/ui-parchment.webp') center/256px repeat;
  padding: 10px 20px;
  text-align: center;
  font-weight: 700;
  font-size: 16.5px;
  color: var(--ink-primary);
  border-bottom: 2px solid var(--border-oak);
  box-shadow: inset 0 -1px 0 rgba(184, 137, 46, 0.4);
}

.ornament-sep {
  height: 2px;
  margin: 12px 0;
  background: linear-gradient(90deg, transparent, var(--border-iron) 20%, var(--accent-gold) 50%, var(--border-iron) 80%, transparent);
  border: 0;
}

/* Boutons et états purement CSS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-primary);
  background: linear-gradient(180deg, #f3e8cf, #d8c59e);
  border: 1px solid #6e5539;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.65);
  transition: filter 100ms ease, transform 80ms ease, background-color 100ms ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.06);
  border-color: #4d3924;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
  filter: brightness(0.95);
}

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.48;
  filter: saturate(0.35);
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #dfbe6f, #b98b32);
  border-color: #694915;
  color: #1f160c;
}

.btn-emerald {
  background: linear-gradient(180deg, #588c66, #3a6b48);
  border-color: #24472e;
  color: #f6f3ea;
}

.btn-danger {
  background: linear-gradient(180deg, #bf584b, #96382d);
  border-color: #5e1f18;
  color: #fdf6f2;
}

.btn-icon { padding: 5px 7px; }

/* Onglets */
.tabs {
  display: flex;
  gap: 4px;
  padding: 6px 14px 0;
  border-bottom: 1px solid var(--border-hairline);
  background: rgba(205, 189, 156, 0.28);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  background: rgba(232, 221, 198, 0.55);
  border: 1px solid var(--border-hairline);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
}

.tab:hover { background: rgba(244, 236, 218, 0.85); color: var(--ink-primary); }
.tab[aria-selected="true"] {
  background: var(--bg-parchment);
  color: var(--ink-primary);
  border-color: #7d6546;
  box-shadow: inset 0 2px 0 var(--accent-gold);
}

/* Cartes, grilles et tableaux */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 10px;
}

.card {
  background: rgba(250, 244, 230, 0.72);
  border: 1px solid rgba(92, 70, 44, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
  background: rgba(90, 66, 46, 0.13);
  border: 1px solid rgba(90, 66, 46, 0.28);
  color: var(--ink-primary);
}

.badge-ally { background: rgba(58, 107, 72, 0.16); border-color: var(--accent-emerald); color: #22462d; }
.badge-nap { background: rgba(56, 101, 127, 0.16); border-color: var(--accent-azure); color: #1f4156; }
.badge-war { background: rgba(158, 61, 50, 0.16); border-color: var(--accent-crimson); color: #681f18; }
.badge-gold { background: rgba(184, 137, 46, 0.2); border-color: var(--accent-gold); color: #543b0d; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12.5px;
}

.data-table th {
  text-align: left;
  padding: 7px 8px;
  background: rgba(190, 173, 139, 0.42);
  border-bottom: 1px solid rgba(90, 66, 46, 0.35);
  color: var(--ink-primary);
  font-weight: 700;
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(90, 66, 46, 0.16);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: rgba(255, 250, 236, 0.65);
}

.cost-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
}

.cost-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: rgba(214, 199, 168, 0.45);
  border-radius: 3px;
}

/* Zone carte / scène interactive */
.viewport-canvas {
  position: relative;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-iron);
  overflow: hidden;
  background: #8ea079;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.viewport-canvas svg.scene-svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.floating-tools {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: rgba(42, 31, 21, 0.86);
  border: 1px solid var(--border-iron);
  border-radius: var(--radius-sm);
}

.floating-overlay-top {
  position: absolute;
  left: 12px;
  top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(90, 66, 46, 0.2);
  font-size: 13px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.form-field label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.input, select, textarea {
  padding: 6px 9px;
  border: 1px solid #7c6345;
  border-radius: var(--radius-sm);
  background: #fbf6ea;
  color: var(--ink-primary);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
}

.shield-coat {
  width: 46px;
  height: 52px;
  background: linear-gradient(180deg, #e8dec6, #cbbe9f);
  border: 2px solid var(--border-iron);
  border-radius: 4px 4px 22px 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.65);
}

.seal-counter {
  width: 24px;
  height: 24px;
  background: radial-gradient(circle at 35% 35%, #bf5244, #7f291f);
  border: 1.5px solid #e2c078;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff6e5;
  font-family: system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
}
