/* 
 Copyright (C) 2026 Nautical-Myles
 Use of this software is govered by the Business Source License included in the LICENSE.md file and at www.mariadb.com/bsl11.
 Change Date: 1 January 2028
 On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE.md file.
*/

/* Version 1.0.0 */

:root {
      --bg-deep: #110d0a;
      --bg-panel: #1f1914;
      --bg-panel-alt: #29211a;
      --bg-parchment-dark: #332920;
      --border-gold: #8c6d3f;
      --border-gold-bright: #cfa358;
      --border-muted: #47392b;
      --text-main: #eee0c5;
      --text-muted: #b09d7c;
      --text-dim: #9b896f;
      --accent-gold: #d9a74a;
      --accent-green: #4e8c45;
      --accent-red: #b84439;
      --accent-blue: #3f78a8;
      --shadow-heavy: 0 8px 24px rgba(0, 0, 0, 0.65);
    }

    * {
      box-sizing: border-box;
      user-select: none;
      -webkit-user-select: none;
    }

    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      background-color: var(--bg-deep);
      color: var(--text-main);
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      font-size: 13px;
    }

    /* === LAYOUT SHELL === */
    #app-shell {
      display: grid;
      grid-template-columns: 350px 1fr;
      grid-template-rows: auto 1fr 30px;
      grid-template-areas:
        "sidebar toolbar"
        "sidebar viewport"
        "sidebar statusbar";
      width: 100vw;
      height: 100vh;
    }

    /* === LEFT SIDEBAR === */
    #sidebar {
      grid-area: sidebar;
      background: linear-gradient(180deg, #241d17 0%, #191410 100%);
      border-right: 2px solid var(--border-gold);
      display: flex;
      flex-direction: column;
      z-index: 20;
      box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
    }

    .brand-header {
      padding: 12px 14px;
      background: linear-gradient(90deg, #2c2219 0%, #1f1812 100%);
      border-bottom: 1px solid var(--border-gold);
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .brand-crest {
      width: 44px;
      height: 44px;
      border-radius: 6px;
      background: radial-gradient(circle, #e3b659 0%, #966b28 100%);
      border: 1px solid #ffdf91;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      color: #1f1710;
      font-weight: bold;
      box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    }

    .brand-title {
      font-family: Georgia, 'Times New Roman', serif;
      font-size: 15px;
      font-weight: 700;
      letter-spacing: 0.5px;
      color: var(--accent-gold);
      text-transform: uppercase;
      line-height: 1.1;
    }

    .brand-subtitle {
      font-size: 11px;
      font-style: italic;
      color: var(--text-muted);
      letter-spacing: 0.3px;
    }

    /* Sidebar Tabs */
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #17120e;
  border-bottom: 1px solid var(--border-gold);
}

.tab-btn {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border-muted);
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  padding: 10px 2px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

    .tab-btn:last-child {
      border-right: none;
    }

    .tab-btn:hover {
      background: rgba(217, 167, 74, 0.08);
      color: var(--text-main);
    }

    .tab-btn.active {
      background: var(--bg-panel-alt);
      color: var(--accent-gold);
      border-bottom-color: var(--accent-gold);
    }

    /* Active Hub Context Banner (Used in Phase 3) */
    #active-hub-banner {
      display: none;
      background: linear-gradient(90deg, #3a2b17 0%, #2b2011 100%);
      border-bottom: 1px solid var(--border-gold-bright);
      padding: 8px 12px;
      font-size: 12px;
      color: #ffdfa0;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    #active-hub-banner.visible {
      display: flex;
    }

    /* Sidebar Content Panels */
    .sidebar-panels {
      flex: 1;
      overflow-y: auto;
      padding: 12px;
    }

    .sidebar-panels::-webkit-scrollbar {
      width: 6px;
    }

    .sidebar-panels::-webkit-scrollbar-track {
      background: #16110d;
    }

    .sidebar-panels::-webkit-scrollbar-thumb {
      background: var(--border-muted);
      border-radius: 3px;
    }

    .sidebar-panels::-webkit-scrollbar-thumb:hover {
      background: var(--border-gold);
    }

    #appearance-control {
      flex: 1 1 100%;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-items: center;
      gap: 8px;
      min-width: 0;
    }

    .appearance-field {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr);
      align-items: center;
      gap: 5px;
      min-width: 0;
    }

    #appearance-control label {
      color: var(--text-muted);
      font-size: 11px;
      font-weight: 600;
    }

    #appearance-control select {
      width: 100%;
      min-width: 0;
      padding: 5px 8px;
      border: 1px solid var(--border-muted);
      border-radius: 4px;
      background: var(--bg-panel-alt);
      color: var(--text-main);
      font-size: 11px;
      cursor: pointer;
    }

    #appearance-control select:focus-visible {
      outline: 2px solid var(--accent-gold);
      outline-offset: 2px;
    }

    .tab-panel {
      display: none;
    }

    .tab-panel.active {
      display: block;
    }

    .panel-placeholder {
      border: 1px dashed var(--border-muted);
      border-radius: 6px;
      padding: 18px 14px;
      text-align: center;
      color: var(--text-muted);
      background: rgba(0, 0, 0, 0.2);
      line-height: 1.5;
    }

    .panel-section-title {
      font-family: Georgia, serif;
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      color: var(--accent-gold);
      margin: 14px 0 8px 0;
      padding-bottom: 4px;
      border-bottom: 1px solid var(--border-muted);
    }

    .panel-section-title:first-child {
      margin-top: 0;
    }

/* === TOP TOOLBAR === */
    #toolbar {
      grid-area: toolbar;
      background: linear-gradient(180deg, #272019 0%, #1c1611 100%);
      border-bottom: 2px solid var(--border-gold);
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      min-height: 50px;
      padding: 6px 12px;
      gap: 6px 8px;
      z-index: 15;
      overflow: hidden;
    }

    .toolbar-group {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 4px;
    }

    .toolbar-divider {
      width: 1px;
      height: 24px;
      background: var(--border-muted);
      margin: 0 2px;
      flex-shrink: 0;
    }

    .tool-btn {
      background: var(--bg-panel-alt);
      border: 1px solid var(--border-muted);
      color: var(--text-main);
      padding: 5px 9px;
      border-radius: 4px;
      font-size: 12px;
      font-weight: 500;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: all 0.12s ease;
      white-space: nowrap;
      flex-shrink: 0;
    }

    .tool-btn:hover {
      border-color: var(--border-gold);
      background: #362b21;
    }

    .tool-btn.active {
      background: linear-gradient(180deg, #523e24 0%, #3b2b17 100%);
      border-color: var(--border-gold-bright);
      color: #ffe2a8;
      box-shadow: inset 0 0 6px rgba(217, 167, 74, 0.35);
    }

    .tool-btn.danger {
      border-color: #6b2c25;
      color: #f2a29b;
    }

    .tool-btn.danger:hover {
      background: #4a1e19;
      border-color: var(--accent-red);
      color: #ffd2ce;
    }

    .kbd-hint {
      font-size: 10px;
      padding: 1px 4px;
      border-radius: 3px;
      background: rgba(0, 0, 0, 0.35);
      color: var(--text-muted);
      border: 1px solid rgba(255, 255, 255, 0.08);
      font-family: monospace;
    }

    /* Toggle Switch for Free Placement */
    .toggle-pill {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 5px 9px;
      border-radius: 4px;
      background: var(--bg-panel-alt);
      border: 1px solid var(--border-muted);
      cursor: pointer;
      font-size: 12px;
      color: var(--text-main);
      white-space: nowrap;
      flex-shrink: 0;
    }

    .toggle-pill.active {
      border-color: var(--accent-green);
      background: rgba(78, 140, 69, 0.2);
      color: #c8f5c1;
    }

    .toggle-pill .toggle-dot {
      width: 9px;
      height: 9px;
      border-radius: 50%;
      background: var(--text-dim);
      transition: background 0.15s ease;
    }

    .toggle-pill.active .toggle-dot {
      background: #6ee061;
      box-shadow: 0 0 6px #6ee061;
    }

    /* Stage 1 Compression: Hide shortcut badges & tighten padding on medium/laptop screens */
    @media (max-width: 1520px) {
      #toolbar {
        padding: 5px 8px;
        gap: 5px 6px;
      }
      .kbd-hint {
        display: none;
      }
      .tool-btn, .toggle-pill {
        padding: 5px 7px;
        font-size: 11.5px;
        gap: 4px;
      }
      .toolbar-divider {
        margin: 0 1px;
      }
    }

    /* Stage 2 Compression: Extra-snug button spacing before wrapping on narrower screens */
    @media (max-width: 1220px) {
      .tool-btn, .toggle-pill {
        padding: 4px 6px;
        font-size: 11px;
      }
      .toolbar-divider {
        display: none;
      }
    }

    /* === MAIN VIEWPORT & FLOATING ELEMENTS === */
    #viewport {
      grid-area: viewport;
      position: relative;
      width: 100%;
      height: 100%;
      overflow: hidden;
      background: #110d0a;
    }

    #startup-splash {
      position: absolute;
      inset: 0;
      z-index: 200;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      padding: 12px;
      background: var(--bg-deep);
      text-align: center;
    }

    #splash-title-card {
      width: 100%;
      height: 0;
      min-height: 0;
      flex: 1 1 auto;
      object-fit: contain;
      margin-bottom: 12px;
      filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.6));
    }

    #splash-actions {
      display: flex;
      flex: 0 0 auto;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
      gap: 8px;
      max-width: 100%;
    }

    #splash-actions .splash-prompt {
      color: var(--text-muted);
      font-family: Georgia, serif;
      font-size: 16px;
    }

    #splash-actions .splash-or {
      color: var(--text-dim);
      font-size: 13px;
      font-style: italic;
    }

    #splash-actions #btn-splash-import {
      flex-shrink: 0;
      font-size: 14px;
      font-weight: 600;
      padding: 10px 20px;
    }

    #splash-actions #btn-splash-blank {
      flex-shrink: 0;
      font-size: 13px;
      padding: 8px 16px;
      color: var(--text-muted);
    }

    #main-canvas {
      display: block;
      width: 100%;
      height: 100%;
      cursor: crosshair;
    }

    #main-canvas.cursor-grab {
      cursor: grab;
    }

    #main-canvas.cursor-grabbing {
      cursor: grabbing;
    }

    /* Floating 5x5 Territory Minimap */
    #minimap-card {
      position: absolute;
      top: 14px;
      right: 14px;
      width: 196px;
      background: rgba(28, 22, 17, 0.94);
      border: 2px solid var(--border-gold);
      border-radius: 6px;
      box-shadow: var(--shadow-heavy);
      padding: 8px;
      z-index: 10;
      backdrop-filter: blur(4px);
    }

    .minimap-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-family: Georgia, serif;
      font-size: 11px;
      font-weight: bold;
      color: var(--accent-gold);
      text-transform: uppercase;
      letter-spacing: 0.6px;
      margin-bottom: 6px;
      padding-bottom: 4px;
      border-bottom: 1px solid var(--border-muted);
    }

    #minimap-canvas {
      display: block;
      width: 176px;
      height: 176px;
      border: 1px solid var(--border-muted);
      border-radius: 3px;
      cursor: pointer;
      background: #17120e;
    }

    .minimap-footer {
      margin-top: 6px;
      font-size: 10px;
      color: var(--text-muted);
      line-height: 1.35;
      text-align: center;
    }

    /* Floating Hover Tooltip */
    #hover-tooltip {
      position: fixed;
      pointer-events: none;
      z-index: 100;
      display: none;
      min-width: 180px;
      max-width: 290px;
      background: rgba(24, 18, 14, 0.96);
      border: 1px solid var(--border-gold-bright);
      border-radius: 5px;
      padding: 8px 10px;
      box-shadow: 0 6px 18px rgba(0, 0, 0, 0.75);
      color: var(--text-main);
      font-size: 12px;
      line-height: 1.4;
    }

    #hover-tooltip .tt-title {
      font-weight: 700;
      color: var(--accent-gold);
      margin-bottom: 3px;
      font-family: Georgia, serif;
    }

    #hover-tooltip .tt-sub {
      font-size: 11px;
      color: var(--text-muted);
      margin-bottom: 4px;
    }

    #hover-tooltip .tt-warn {
      margin-top: 5px;
      padding-top: 5px;
      border-top: 1px solid rgba(184, 68, 57, 0.45);
      color: #ff948a;
      font-size: 11px;
    }

    /* === BOTTOM STATUS BAR === */
    #statusbar {
      grid-area: statusbar;
      background: #17120e;
      border-top: 1px solid var(--border-gold);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 14px;
      font-size: 11.5px;
      color: var(--text-muted);
      z-index: 20;
    }

    .status-group {
      display: flex;
      align-items: center;
      gap: 14px;
    }

    .status-item strong {
      color: var(--text-main);
      font-weight: 600;
    }

    .status-badge {
      display: inline-block;
      padding: 1px 6px;
      border-radius: 3px;
      font-size: 10.5px;
      font-weight: 600;
      text-transform: uppercase;
    }

    .status-badge.active {
      background: rgba(78, 140, 69, 0.25);
      color: #9be890;
      border: 1px solid #4e8c45;
    }

    .status-badge.unbought {
      background: rgba(176, 157, 124, 0.15);
      color: #cbb894;
      border: 1px solid #6e5d45;
    }

    /* Shared UI Grid / Button styles for Phases 2-5 */
    .item-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 6px;
    }

    .palette-btn {
      background: var(--bg-panel-alt);
      border: 1px solid var(--border-muted);
      border-radius: 4px;
      padding: 7px 8px;
      color: var(--text-main);
      text-align: left;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 11.5px;
      transition: all 0.12s ease;
    }

    .palette-btn:hover {
      border-color: var(--border-gold);
      background: #34291f;
    }

    .palette-btn.active {
      background: linear-gradient(180deg, #4f3b21 0%, #382915 100%);
      border-color: var(--border-gold-bright);
      color: #ffe5ad;
    }

    .swatch {
      width: 16px;
      height: 16px;
      border-radius: 3px;
      border: 1px solid rgba(255, 255, 255, 0.25);
      flex-shrink: 0;
    }