@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

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

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: #0d0d0d;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-bottom: 1px solid #2a2a4a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

header h1 {
    font-size: 1.4em;
    font-weight: 700;
    background: linear-gradient(90deg, #ffa500, #ff6347);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.fight-subphase-label {
    padding: 4px 10px;
    border: 1px solid #66bb6a;
    border-radius: 6px;
    background: rgba(46, 125, 50, 0.2);
    color: #a5d6a7;
    font-size: 0.85em;
    font-weight: 700;
}

.toolbar label,
.toolbar button {
    font-size: 0.85em;
}

.toolbar button {
    padding: 6px 14px;
    border: 1px solid #555;
    border-radius: 6px;
    background: linear-gradient(145deg, #2a2a4a, #1a1a2e);
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.toolbar button:hover {
    background: linear-gradient(145deg, #3a3a6a, #2a2a4e);
    border-color: #ffa500;
    color: #ffa500;
    box-shadow: 0 0 8px rgba(255, 165, 0, 0.25);
}

.toolbar button.active {
    border-color: #ffa500;
    color: #ffa500;
    background: linear-gradient(145deg, #16213e, #1a1a2e);
    box-shadow: inset 0 0 10px rgba(255, 165, 0, 0.3);
}

.toolbar button.topbar-btn--special {
    background: linear-gradient(145deg, #ffa500, #ff6347);
    border-color: #ffca28;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 0 15px rgba(255, 165, 0, 0.45);
}

.toolbar button.topbar-btn--danger {
    background: linear-gradient(145deg, #3a1a1a, #2a1010);
    border-color: #c0392b;
    color: #ff8a80;
    font-weight: 700;
}

.toolbar button.topbar-btn--confirm {
    background: linear-gradient(145deg, #2e7d32, #1b5e20);
    border-color: #66bb6a;
    color: #e8f5e9;
    font-weight: 700;
}

.toolbar button.topbar-btn--confirm.is-advanced {
    background: linear-gradient(145deg, #4a4a4a, #333);
    border-color: #8a8a8a;
    color: #d6d6d6;
    box-shadow: none;
}

.toolbar button:disabled {
    cursor: not-allowed;
    opacity: 0.72;
}

.map-setup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2100;
}

.map-setup-overlay.visible {
    display: flex;
}

.map-setup-modal {
    width: min(92vw, 380px);
    background: linear-gradient(145deg, #1a1a2e, #16213e);
    border: 1px solid #3a3a6a;
    border-radius: 10px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
    padding: 16px;
}

.map-setup-modal h3 {
    color: #ffa500;
    margin-bottom: 12px;
    font-size: 1rem;
}

.map-setup-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.map-setup-row label {
    font-size: 0.85rem;
    color: #c8d1e8;
}

.map-setup-row input {
    background: rgba(10, 10, 30, 0.9);
    color: #f4f6fb;
    border: 1px solid #3a3a6a;
    border-radius: 6px;
    padding: 8px 10px;
    font: inherit;
}

.map-setup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.map-setup-actions button {
    min-width: 92px;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 700;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.map-setup-actions button:hover {
    transform: translateY(-1px);
}

.map-setup-actions button:active {
    transform: translateY(0);
}

.map-setup-actions .map-setup-cancel {
    border: 1px solid #5b6486;
    background: linear-gradient(145deg, #20263a, #1a1f31);
    color: #cfd7ee;
}

.map-setup-actions .map-setup-cancel:hover {
    border-color: #7a86af;
    box-shadow: 0 4px 14px rgba(70, 85, 130, 0.3);
}

.map-setup-actions .map-setup-ok {
    border: 1px solid #ffb547;
    background: linear-gradient(145deg, #ffb347, #ff7d45);
    color: #1d1206;
    box-shadow: 0 4px 16px rgba(255, 145, 72, 0.35);
}

.map-setup-actions .map-setup-ok:hover {
    border-color: #ffd08a;
    box-shadow: 0 6px 20px rgba(255, 145, 72, 0.45);
}

.map-container {
    margin: 20px;
    overflow: hidden;
    width: calc(100vw - 40px);
    height: calc(100vh - 120px);
    border: 2px solid #2a2a4a;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.6), inset 0 0 60px rgba(0, 0, 0, 0.3);
    position: relative;
    user-select: none;
}

.canvas-wrap {
    position: relative;
    display: inline-block;
}

canvas {
    display: block;
    cursor: default;
}

.tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(10, 10, 30, 0.94);
    border: 1px solid #ffa500;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.82em;
    line-height: 1.5;
    color: #e0e0e0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6), 0 0 10px rgba(255, 165, 0, 0.15);
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
    max-width: 260px;
    white-space: nowrap;
}

.tooltip.visible {
    opacity: 1;
}

.tooltip .tt-name {
    font-weight: 700;
    color: #ffa500;
    font-size: 1.05em;
    margin-bottom: 2px;
}

.tooltip .tt-unit {
    font-size: 0.9em;
    color: #aaa;
    margin-bottom: 6px;
}

.tooltip .tt-stats {
    display: flex;
    gap: 10px;
    margin-bottom: 4px;
}

.tooltip .tt-stats span {
    background: #222;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.tooltip .tt-weapons {
    border-top: 1px solid #333;
    padding-top: 4px;
    margin-top: 4px;
    color: #ccc;
    font-size: 0.88em;
}

/* ── LEGEND FLYOUT ── */
.legend-flyout {
    position: fixed;
    top: 120px;
    bottom: 0;
    right: 0;
    transform: translateX(0);
    transition: transform 0.3s ease;
    display: flex;
    align-items: stretch;
    z-index: 1100;
}

.legend-flyout.collapsed {
    transform: translateX(calc(100% - 28px));
}

.legend-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    width: 28px;
    padding: 16px 6px;
    background: linear-gradient(180deg, #2a2a4a, #1a1a2e);
    border: 1px solid #3a3a6a;
    border-right: none;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    font-size: 0.75em;
    font-weight: 600;
    color: #ffa500;
    letter-spacing: 1px;
    user-select: none;
    transition: background 0.2s;
    flex-shrink: 0;
}

.legend-tab:hover {
    background: linear-gradient(180deg, #3a3a6a, #2a2a4e);
}

.legend-tab .tab-arrow {
    display: block;
    margin-top: 8px;
    font-size: 1.1em;
    transition: transform 0.3s;
    writing-mode: horizontal-tb;
}

.legend-flyout.collapsed .tab-arrow {
    transform: scaleX(-1);
}

.legend-panel {
    background: rgba(10, 10, 30, 0.95);
    border: 1px solid #3a3a6a;
    border-right: none;
    padding: 14px 16px;
    font-size: 0.8em;
    min-width: 320px;
    max-width: 420px;
    height: 100%;
    max-height: none;
    overflow-y: auto;
}

.legend-panel h3 {
    font-size: 0.85em;
    font-weight: 700;
    color: #ffa500;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #333;
}

/* ── LOG AREA ─────────────────────────────────────── */
.legend-army-tabs {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    margin-bottom: 10px;
    border-bottom: 1px solid #3a3a6a;
    padding: 0 2px;
}

.legend-filters {
    display: flex;
    margin-bottom: 10px;
}

.legend-filter-btn {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #505088;
    border-radius: 7px;
    background: linear-gradient(145deg, #2b2b4f, #1d1d33);
    color: #e0e0f0;
    font-size: 0.82em;
    cursor: pointer;
}

.legend-filter-btn.active {
    border-color: #ffa500;
    color: #ffa500;
}

.legend-deploying-status {
    margin-top: 6px;
    color: #ffca6b;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.legend-army-tab {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid #3a3a6a;
    border-bottom: none;
    background: linear-gradient(180deg, rgba(34, 40, 64, 0.9), rgba(20, 24, 40, 0.95));
    color: #95a2c4;
    border-radius: 8px 8px 0 0;
    padding: 11px 18px 9px;
    font-size: 1.275em;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
    transform: translateY(1px);
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.legend-army-tab:not(.active) {
    border-bottom: 1px solid #3a3a6a;
    box-shadow: none;
}

.legend-army-tab:hover {
    color: #d8ecff;
    background: linear-gradient(180deg, rgba(52, 66, 104, 0.9), rgba(24, 34, 58, 0.95));
}

.legend-army-tab.active {
    color: #ffa500;
    background: rgba(10, 10, 30, 0.95);
    transform: translateY(1px);
    position: relative;
    z-index: 1;
}

.legend-empty {
    border: 1px dashed rgba(174, 184, 212, 0.4);
    border-radius: 8px;
    padding: 10px;
    color: #aeb8d4;
    text-align: center;
    font-size: 0.9em;
}

#map-log-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(20, 20, 20, 0.95);
    border-top: 2px solid #444;
    color: #eee;
    font-family: 'Consolas', 'Courier New', monospace;
    z-index: 1000;
    transition: transform 0.3s ease;
    transform: translateY(calc(100% - 30px));
}

#map-log-container.expanded {
    transform: translateY(0);
}

#map-log-header {
    background: #333;
    padding: 5px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 30px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #ffa500;
}

#map-log-content {
    height: 225px;
    overflow-y: auto;
    padding: 10px 15px;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.log-entry {
    margin-bottom: 4px;
    border-left: 3px solid #666;
    padding-left: 8px;
}

.log-phase {
    color: #4fc3f7;
    font-weight: bold;
}

.log-turn {
    color: #ffa500;
    font-weight: bold;
    border-top: 1px solid #444;
    padding-top: 5px;
    margin-top: 5px;
}

.log-move {
    color: #a5d6a7;
}

.legend-unit-browser-item {
    border: 1px solid rgba(79, 195, 247, 0.2);
    border-radius: 8px;
    padding: 8px;
    margin: 8px 0;
    background: rgba(255, 255, 255, 0.03);
}

.legend-unit-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-unit-header-main {
    flex: 1;
    min-width: 0;
}

.legend-unit-name {
    color: #f0f0f0;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.legend-unit-summary {
    color: #a0a0b5;
    font-size: 0.9em;
    margin-top: 2px;
}

.legend-unit-toggle-btn {
    background: transparent;
    border: 1px solid #4fc3f7;
    color: #4fc3f7;
    border-radius: 4px;
    width: 26px;
    height: 24px;
    padding: 0;
    font-size: 1em;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.legend-unit-toggle-btn:hover {
    border-color: #ffa500;
    color: #ffa500;
}

.legend-model-list {
    margin-top: 8px;
}

.legend-model-list .model-list-item {
    cursor: grab;
}

.legend-model-list .model-weapons-row {
    max-height: none;
    opacity: 1;
    margin-top: 4px;
    padding-top: 4px;
    font-style: normal;
    color: #aeb8d4;
    line-height: 1.35;
}

.legend-model-list .model-list-item:hover .model-weapons-row {
    max-height: none;
    opacity: 1;
}

.legend-model-list .model-list-item.dragging {
    opacity: 0.45;
}

.legend-model-list .model-list-item.drag-over-before {
    box-shadow: inset 0 2px 0 #ffa500;
    background: rgba(255, 165, 0, 0.1);
}

.legend-model-list .model-list-item.drag-over-after {
    box-shadow: inset 0 -2px 0 #ffa500;
    background: rgba(255, 165, 0, 0.1);
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 4px currentColor;
}

.import-input {
    display: none;
}

/* ── PHASE BAR ── */
.phase-bar {
    width: 100%;
    max-width: 900px;
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin: 10px 0;
    padding: 0 4px;
}

.phase-turn {
    flex: 0 0 auto;
    min-width: 90px;
    padding: 6px 10px;
    text-align: center;
    font-size: 1em;
    line-height: 1;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: transparent;
    border: none;
    border-radius: 0;
    color: #ffa500;
    box-shadow: none;
}

.phase-cp {
    flex: 0 0 auto;
    min-width: 140px;
    padding: 6px 10px;
    text-align: center;
    font-size: 0.9em;
    line-height: 1;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #f4d35e;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.phase-cp .cp-side-l {
    color: #4fc3f7;
}

.phase-cp .cp-side-r {
    color: #ef5350;
}

.phase-step {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: #1a1a2e;
    border: 1px solid #2a2a4a;
    border-radius: 4px;
    color: #666;
    transition: all 0.3s;
    position: relative;
}

.phase-step.active {
    color: #fff;
    border-color: #ffa500;
    box-shadow: 0 0 10px rgba(255, 165, 0, 0.3);
    background: #16213e;
}

.phase-step.side-l.active {
    border-color: #4fc3f7;
    color: #4fc3f7;
}

.phase-step.side-r.active {
    border-color: #81c784;
    color: #81c784;
}

.phase-step .phase-side {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6em;
    background: #0d0d0d;
    padding: 0 4px;
}
