"""Zentrales Design-System der PilotNG-App.

Glassmorphism-Edition: atmosphaerischer Verlauf, schwebende Panels
mit weichem Schatten und grosser Rundung — waehlbar als Dunkel- oder
Hell-Modus, mit Akzentfarbe und Glas-Staerke (Reiter Einstellungen
-> Design). Alle Seiten lesen die Werte hier, setTheme/setMode/
setGlassIntensity schalten live um.
"""

# ------------------------------------------------------------- Modi
MODES = {
    'dunkel': {
        'BG': '#0A0E16', 'SIDEBAR_TOP': '#111A2C', 'SIDEBAR_BOTTOM': '#0A0E18',
        'SURFACE': '#141C2B', 'ELEVATED': '#1D2839',
        'BORDER': '#26334A', 'GLASS_EDGE': '#31405C',
        'TEXT': '#EDF1F7', 'MUTED': '#93A0B4', 'FAINT': '#5E6B80',
        'PANEL_TOP': '#212D44', 'PANEL_BOTTOM': '#182134',
        'PANEL_CENTER': '#1B2638', 'PANEL_EDGE': '#41577A',
        'SHADOW_RGB': (0, 0, 0), 'SHADOW_ALPHA': 160,
        'GLOW_ALPHA': 50,
    },
    'hell': {
        'BG': '#E7EDF5', 'SIDEBAR_TOP': '#FFFFFF', 'SIDEBAR_BOTTOM': '#E9F0F8',
        'SURFACE': '#FFFFFF', 'ELEVATED': '#F0F4FA',
        'BORDER': '#DCE4EF', 'GLASS_EDGE': '#FFFFFF',
        'TEXT': '#16233A', 'MUTED': '#64748B', 'FAINT': '#94A3B8',
        'PANEL_TOP': '#FFFFFF', 'PANEL_BOTTOM': '#F1F5FA',
        'PANEL_CENTER': '#FAFCFE', 'PANEL_EDGE': '#FFFFFF',
        'SHADOW_RGB': (31, 48, 74), 'SHADOW_ALPHA': 70,
        'GLOW_ALPHA': 70,
    },
}
DEFAULT_MODE = 'dunkel'
MODE_LABELS = {'dunkel': 'Dunkel', 'hell': 'Hell'}

THEME_NAME = None  # wird unten gesetzt
MODE_NAME = DEFAULT_MODE
GLASS_INTENSITY = 100  # 0-100, Regler in den Einstellungen


def _applyMode(name):
    global BG, SIDEBAR, SIDEBAR_TOP, SIDEBAR_BOTTOM, SURFACE, ELEVATED
    global BORDER, GLASS_EDGE, TEXT, MUTED, FAINT
    global PANEL_TOP, PANEL_BOTTOM, PANEL_CENTER, PANEL_EDGE
    global SHADOW_RGB, SHADOW_ALPHA_BASE, GLOW_ALPHA_BASE, MODE_NAME
    mode = MODES.get(name, MODES[DEFAULT_MODE])
    MODE_NAME = name if name in MODES else DEFAULT_MODE
    BG = mode['BG']
    SIDEBAR = mode['SIDEBAR_TOP']
    SIDEBAR_TOP = mode['SIDEBAR_TOP']
    SIDEBAR_BOTTOM = mode['SIDEBAR_BOTTOM']
    SURFACE = mode['SURFACE']
    ELEVATED = mode['ELEVATED']
    BORDER = mode['BORDER']
    GLASS_EDGE = mode['GLASS_EDGE']
    TEXT = mode['TEXT']
    MUTED = mode['MUTED']
    FAINT = mode['FAINT']
    PANEL_TOP = mode['PANEL_TOP']
    PANEL_BOTTOM = mode['PANEL_BOTTOM']
    PANEL_CENTER = mode['PANEL_CENTER']
    PANEL_EDGE = mode['PANEL_EDGE']
    SHADOW_RGB = mode['SHADOW_RGB']
    SHADOW_ALPHA_BASE = mode['SHADOW_ALPHA']
    GLOW_ALPHA_BASE = mode['GLOW_ALPHA']


def setMode(name):
    """Hell/Dunkel umschalten (Seiten neu bauen -> Application)."""
    _applyMode(name)
    setTheme(THEME_NAME)  # ACCENT_SOFT passend zum Modus neu mischen


def setGlassIntensity(value):
    """Glas-Staerke 0-100: skaliert Schatten, Kante und Glow."""
    global GLASS_INTENSITY
    GLASS_INTENSITY = max(0, min(100, int(value)))


_applyMode(DEFAULT_MODE)

SUCCESS = '#3FB68B'
WARNING = '#E0A23B'
DANGER = '#E5484D'

# ------------------------------------------------------- Akzent-Themen
THEMES = {
    'rosa':    {'accent': '#E33A63', 'hover': '#F0557B', 'soft': '#2A1626'},
    'violett': {'accent': '#8B5CF6', 'hover': '#A78BFA', 'soft': '#241C38'},
    'cyan':    {'accent': '#06B6D4', 'hover': '#22D3EE', 'soft': '#102A33'},
    'gruen':   {'accent': '#22C55E', 'hover': '#4ADE80', 'soft': '#14291C'},
    'amber':   {'accent': '#F59E0B', 'hover': '#FBBF24', 'soft': '#33270F'},
    'blau':    {'accent': '#3B82F6', 'hover': '#60A5FA', 'soft': '#16233C'},
}
DEFAULT_THEME = 'rosa'
THEME_LABELS = {
    'rosa': 'Rosa', 'violett': 'Violett', 'cyan': 'Cyan',
    'gruen': 'Grün', 'amber': 'Amber', 'blau': 'Blau',
}

THEME_NAME = DEFAULT_THEME
ACCENT = THEMES[DEFAULT_THEME]['accent']
ACCENT_HOVER = THEMES[DEFAULT_THEME]['hover']
ACCENT_SOFT = THEMES[DEFAULT_THEME]['soft']


def setTheme(name):
    """Akzentfarbe live umschalten (Seiten neu bauen -> Application)."""
    global THEME_NAME, ACCENT, ACCENT_HOVER, ACCENT_SOFT
    theme = THEMES.get(name, THEMES[DEFAULT_THEME])
    THEME_NAME = name if name in THEMES else DEFAULT_THEME
    ACCENT = theme['accent']
    ACCENT_HOVER = theme['hover']
    # Soft-Variante passend zum Modus (hell/dunkel) mischen.
    ACCENT_SOFT = mix(SURFACE, ACCENT, 0.18)


def mix(hexA, hexB, t):
    """Zwischen zwei Hex-Farben interpolieren (Hover-Animation)."""
    a = tuple(int(hexA[i:i + 2], 16) for i in (1, 3, 5))
    b = tuple(int(hexB[i:i + 2], 16) for i in (1, 3, 5))
    return '#%02X%02X%02X' % tuple(
        round(a[i] + (b[i] - a[i]) * t) for i in range(3))


# Icon-Glyphen (Text-Icons, ein Stil, keine Emojis)
ICON_DASHBOARD = '◧'
ICON_CAVEBOT = '◎'
ICON_HEALING = '✚'
ICON_COMBO = '⚡'
ICON_INVENTORY = '▤'
ICON_CONFIG = '⚙'
ICON_ACCOUNT = '◉'
ICON_DEATH = '✝'
ICON_PLAY = '▶'
ICON_PAUSE = '⏸'
ICON_OVERLAY = '▣'
ICON_UPDATE = '↻'
ICON_DOT_ON = '●'
ICON_DOT_OFF = '○'


def font(size=13, weight='normal'):
    import customtkinter
    return customtkinter.CTkFont(family='Segoe UI', size=size, weight=weight)
