/* ============================================================
   APEX & ABYSS — UI DESIGN SYSTEM ("Gilded Campaign")
   Gold-on-parchment, FFT/Wartales painterly direction.
   Single source of truth for UI tokens + shared components.
   Scenes may still carry scene-specific styles, but colors,
   type, spacing and controls must come from these tokens.
   Target: Android phones, 360–412px portrait, 48dp touch.
   ============================================================ */

:root {
    /* --- Ink (warm darks — page + panel grounds) --- */
    --aa-ink-950: #0a0805;
    --aa-ink-900: #14100b;   /* page base */
    --aa-ink-800: #1a1410;   /* deep panel */
    --aa-ink-700: #241a12;   /* mid panel */
    --aa-ink-600: #2d1f15;   /* raised panel */
    --aa-ink-500: #3a2c1e;   /* hover / raised edge */

    /* --- Gold (the signature accent) --- */
    --aa-gold: #d4af37;
    --aa-gold-bright: #ffd76b;
    --aa-gold-deep: #a47f07;
    --aa-bronze: #8b6914;

    /* --- Lines / borders --- */
    --aa-line: #5a4d3a;
    --aa-line-soft: #3a342a;
    --aa-line-gold: rgba(212, 175, 55, 0.45);

    /* --- Parchment text ramp --- */
    --aa-text-bright: #f3e6c8;
    --aa-text: #e6d5b8;
    --aa-text-dim: #cbb98f;
    --aa-text-faint: #9a854f;
    --aa-text-on-gold: #1a1410;

    /* --- Status --- */
    --aa-success: #7fe089;
    --aa-success-deep: #2e6b3f;
    --aa-danger: #e0584f;
    --aa-danger-deep: #7f1d1d;
    --aa-warning: #f5a623;

    /* --- Rarity (warmed to sit on parchment-dark) --- */
    --rarity-common: #a89f91;
    --rarity-uncommon: #6fb46f;
    --rarity-rare: #5a9bd4;
    --rarity-epic: #a86fc9;
    --rarity-legendary: #ffd700;
    --rarity-mythic: #ff6b5e;

    /* --- Legacy aliases (older code reads these names) --- */
    --bg-color: var(--aa-ink-900);
    --surface-color: var(--aa-ink-800);
    --primary-color: var(--aa-gold);
    --secondary-color: var(--aa-gold-bright);
    --text-color: var(--aa-text);

    /* --- Geometry --- */
    --aa-radius: 10px;
    --aa-radius-lg: 14px;
    --aa-touch: 48px;
    --aa-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
    --aa-glow-gold: 0 0 24px rgba(212, 175, 55, 0.25);

    /* --- Shared gradients --- */
    --aa-grad-page: radial-gradient(ellipse at 50% 0%, #241a12 0%, #14100b 62%, #0a0805 100%);
    --aa-grad-panel: linear-gradient(160deg, rgba(45, 31, 21, 0.94), rgba(26, 20, 16, 0.96));
    --aa-grad-gold: linear-gradient(to bottom, var(--aa-gold-bright), var(--aa-gold-deep));
    --aa-grad-ghost: linear-gradient(135deg, rgba(74, 55, 40, 0.55), rgba(45, 31, 21, 0.55));
}

/* ============================================================
   BASE
   ============================================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    cursor: url('../assets/Cursors/cusor_default.png') 0 0, auto;
    -webkit-tap-highlight-color: transparent;
}

canvas {
    cursor: url('../assets/Cursors/cursor_fighting.png') 16 16, crosshair;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--aa-ink-950);
    color: var(--aa-text);
    height: 100vh;
    display: flex;
    justify-content: center;
    overflow: hidden;
    overscroll-behavior: none;
}

#app {
    width: 100%;
    background: var(--aa-grad-page);
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

h1, h2, h3, .aa-display {
    font-family: 'Cinzel', serif;
    color: var(--aa-gold);
    letter-spacing: 0.04em;
}

button {
    font-family: inherit;
    color: inherit;
}

main {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.hidden {
    display: none !important;
}

/* ============================================================
   COMPONENTS — page & header
   ============================================================ */

/* Full-bleed scene wrapper */
.aa-page {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--aa-grad-page);
}

/* Unified scene header: [back] [title/sub] [chips] */
.aa-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: linear-gradient(to bottom, rgba(10, 8, 5, 0.85), rgba(10, 8, 5, 0.35));
    border-bottom: 1px solid var(--aa-line-soft);
}

.aa-topbar .aa-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aa-title {
    font-family: 'Cinzel', serif;
    font-size: 1.18rem;
    font-weight: 700;
    color: var(--aa-gold);
    letter-spacing: 0.06em;
    text-shadow: 0 2px 10px rgba(212, 175, 55, 0.35);
}

.aa-sub {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--aa-text-faint);
    letter-spacing: 0.04em;
}

/* Back / icon button — guaranteed touch size */
.aa-back {
    flex: 0 0 auto;
    min-width: var(--aa-touch);
    min-height: var(--aa-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(192, 160, 98, 0.12);
    border: 1px solid var(--aa-line);
    border-radius: var(--aa-radius);
    color: var(--aa-gold);
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.aa-back:active {
    transform: scale(0.95);
    background: rgba(192, 160, 98, 0.22);
}

/* Resource pill (gold / gems / scrolls / energy) */
.aa-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--aa-line-soft);
    border-radius: 999px;
    padding: 5px 12px;
    min-height: 30px;
    font-size: 0.8rem;
    color: var(--aa-text);
    white-space: nowrap;
}

.aa-chip b {
    color: var(--aa-gold-bright);
    font-weight: 600;
}

/* ============================================================
   COMPONENTS — panels
   ============================================================ */

.aa-panel {
    background: var(--aa-grad-panel);
    border: 1px solid var(--aa-line);
    border-radius: var(--aa-radius-lg);
    box-shadow: var(--aa-shadow);
    padding: 14px;
}

/* Featured / hero panel: gilded frame + glow */
.aa-panel--gold {
    border: 2px solid var(--aa-gold);
    box-shadow: var(--aa-shadow), var(--aa-glow-gold);
}

/* Inset well (slots, lists, empty states) */
.aa-well {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--aa-line-soft);
    border-radius: var(--aa-radius);
}

/* Thin gilded rule, as on the boot screen */
.aa-divider {
    height: 1px;
    border: 0;
    background: linear-gradient(90deg, transparent, var(--aa-bronze), transparent);
    margin: 12px auto;
    width: 70%;
}

/* Small-caps section heading */
.aa-section-label {
    font-family: 'Cinzel', serif;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--aa-text-faint);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin: 4px 2px 8px;
}

/* List row (quests, leaderboard entries, inventory lines) */
.aa-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(45, 31, 21, 0.55);
    border: 1px solid var(--aa-line-soft);
    border-radius: var(--aa-radius);
    padding: 10px 12px;
    min-height: var(--aa-touch);
}

.aa-row + .aa-row {
    margin-top: 8px;
}

/* ============================================================
   COMPONENTS — buttons
   ============================================================ */

.aa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--aa-touch);
    padding: 12px 22px;
    border-radius: var(--aa-radius);
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, filter 0.15s, box-shadow 0.15s;
    user-select: none;
}

.aa-btn:active {
    transform: scale(0.97);
}

.aa-btn--primary {
    background: var(--aa-grad-gold);
    border-color: var(--aa-bronze);
    color: var(--aa-text-on-gold);
    box-shadow: 0 3px 12px rgba(212, 175, 55, 0.35);
}

.aa-btn--primary:active {
    filter: brightness(0.92);
}

.aa-btn--ghost {
    background: var(--aa-grad-ghost);
    border-color: var(--aa-line);
    color: var(--aa-gold);
}

.aa-btn--danger {
    background: linear-gradient(to bottom, #a8453c, var(--aa-danger-deep));
    border-color: #5e1714;
    color: var(--aa-text-bright);
}

.aa-btn--success {
    background: linear-gradient(to bottom, #4e9e5f, var(--aa-success-deep));
    border-color: #1d4427;
    color: var(--aa-text-bright);
}

.aa-btn[disabled],
.aa-btn--disabled {
    background: linear-gradient(to bottom, #3a342a, #241f18);
    border-color: var(--aa-line-soft);
    color: var(--aa-text-faint);
    cursor: default;
    box-shadow: none;
    filter: saturate(0.4);
    pointer-events: none;
}

/* Compact variant for tight rows (still ≥40px; pair with margin) */
.aa-btn--sm {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.82rem;
}

/* ============================================================
   COMPONENTS — tabs
   ============================================================ */

.aa-tabs {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.3);
    overflow-x: auto;
    scrollbar-width: none;
}

.aa-tabs::-webkit-scrollbar {
    display: none;
}

.aa-tab {
    flex: 1 0 auto;
    min-height: 44px;
    padding: 8px 14px;
    border-radius: var(--aa-radius);
    background: rgba(192, 160, 98, 0.06);
    border: 1px solid var(--aa-line-soft);
    color: var(--aa-text-dim);
    font-family: 'Cinzel', serif;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.aa-tab.active {
    background: linear-gradient(to bottom, rgba(212, 175, 55, 0.28), rgba(164, 127, 7, 0.18));
    border-color: var(--aa-gold);
    color: var(--aa-gold-bright);
    box-shadow: inset 0 0 12px rgba(212, 175, 55, 0.12);
}

/* ============================================================
   COMPONENTS — progress bars
   ============================================================ */

.aa-bar {
    width: 100%;
    height: 10px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--aa-line-soft);
    border-radius: 6px;
    overflow: hidden;
}

.aa-bar-fill {
    height: 100%;
    background: var(--aa-grad-gold);
    border-radius: 5px;
    transition: width 0.3s ease;
}

.aa-bar-fill--hp { background: linear-gradient(to bottom, #6fcf7c, #2e6b3f); }
.aa-bar-fill--mp { background: linear-gradient(to bottom, #6aa6e0, #2d5e8f); }
.aa-bar-fill--xp { background: var(--aa-grad-gold); }

/* ============================================================
   COMPONENTS — modal (class twins of ui_modal.js)
   ============================================================ */

.aa-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 3, 2, 0.84);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.18s ease;
}

.aa-modal {
    background: var(--aa-grad-panel);
    border: 2px solid var(--aa-gold);
    border-radius: var(--aa-radius-lg);
    padding: 24px 22px;
    max-width: 400px;
    width: 100%;
    max-height: 86vh;
    overflow-y: auto;
    text-align: center;
    font-family: 'Cinzel', serif;
    color: var(--aa-text);
    box-shadow: 0 0 40px rgba(212, 175, 55, 0.3);
    animation: popIn 0.25s ease;
}

.aa-modal .aa-title {
    margin-bottom: 10px;
}

/* ============================================================
   RARITY
   ============================================================ */

.rarity-border-common { border-color: var(--rarity-common); }
.rarity-border-uncommon { border-color: var(--rarity-uncommon); }
.rarity-border-rare { border-color: var(--rarity-rare); }
.rarity-border-epic { border-color: var(--rarity-epic); }
.rarity-border-legendary { border-color: var(--rarity-legendary); }
.rarity-border-mythic { border-color: var(--rarity-mythic); }

.rarity-text-common { color: var(--rarity-common); }
.rarity-text-uncommon { color: var(--rarity-uncommon); }
.rarity-text-rare { color: var(--rarity-rare); }
.rarity-text-epic { color: var(--rarity-epic); }
.rarity-text-legendary { color: var(--rarity-legendary); }
.rarity-text-mythic { color: var(--rarity-mythic); }

@keyframes legendaryPulse {
    from { box-shadow: 0 0 18px rgba(255, 215, 0, 0.35); }
    to { box-shadow: 0 0 38px rgba(255, 215, 0, 0.75); }
}

/* Level-up reveal card pop-in (see _showLevelUpReveal in tactical_battle_scene) */
@keyframes aa-levelup-pop {
    0%   { transform: scale(0.7); opacity: 0; }
    60%  { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); }
}
.aa-levelup-card { animation: aa-levelup-pop 0.45s cubic-bezier(0.2, 0.8, 0.3, 1.2) both; }

/* ============================================================
   TOWN MAP HUB (live legacy classes, re-skinned to tokens)
   ============================================================ */

.map-location {
    position: absolute;
    cursor: pointer;
    transition: filter 0.2s, transform 0.15s;
    z-index: 5;
}

.map-location:hover {
    filter: brightness(1.3);
    transform: scale(1.05);
}

.map-location:active {
    transform: scale(0.97);
}

.loc-highlight {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.25) 0%, transparent 70%);
    pointer-events: none;
    animation: blink 2s infinite;
}

.loc-label {
    position: absolute;
    background: rgba(20, 16, 11, 0.95);
    color: var(--aa-gold);
    padding: 5px 11px;
    border-radius: 7px;
    font-size: 0.75rem;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.03em;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 20;
    border: 1px solid var(--aa-line-gold);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

.map-location:hover + .loc-label,
.loc-label.visible {
    opacity: 1;
}

/* ============================================================
   LEGACY BATTLE HUD (battle.js — old real-time mode)
   ============================================================ */

.skill-btn {
    border: 2px solid var(--aa-line-gold);
    border-radius: 50%;
    color: var(--aa-text-bright);
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Cinzel', serif;
}

.skill-btn.small {
    width: 50px;
    height: 50px;
    font-size: 1rem;
}

.skill-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ============================================================
   TUTORIAL HIGHLIGHT (tutorial.js outlines targets)
   ============================================================ */

.tutorial-active {
    outline: 2px solid var(--aa-gold) !important;
    outline-offset: 2px;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.5) !important;
    z-index: 100 !important;
    position: relative;
}

/* ============================================================
   FOCUS / ACCESSIBILITY / MOTION
   ============================================================ */

button:focus-visible,
.aa-btn:focus-visible,
.aa-tab:focus-visible {
    outline: 2px solid var(--aa-gold);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================
   KEYFRAMES (shared; several are referenced from JS inline styles)
   ============================================================ */

@keyframes fadeUp {
    0% { opacity: 0; transform: translate(-50%, 20px); }
    20% { opacity: 1; transform: translate(-50%, 0); }
    80% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -20px); }
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.3); }
    80% { transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-30px); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes blink {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

@keyframes shimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

/* ============================================================
   SCROLLBAR (warm, minimal)
   ============================================================ */

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.25);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 175, 55, 0.45);
}

/* ============================================================
   SMALL PHONES (≤360px)
   ============================================================ */

@media (max-width: 360px) {
    .aa-title { font-size: 1.05rem; }
    .aa-chip { padding: 4px 9px; font-size: 0.74rem; }
    .aa-btn { padding: 10px 16px; font-size: 0.88rem; }
    .aa-tab { font-size: 0.76rem; padding: 8px 10px; }
}
