
        :root {
            --bg-color: #121212;
            --panel-bg: #1a1a1a;
            --text-main: #e0e0e0;
            --text-muted: #888;
            --accent: #d4af37;
            --grid-bg: #222;
        }

        /* --- Золотой скроллбар OSRS --- */
        ::-webkit-scrollbar { width: 8px; height: 8px; }
        ::-webkit-scrollbar-track { background: #121215; border-radius: 4px; }
        ::-webkit-scrollbar-thumb { background: #ffd166; border-radius: 4px; box-shadow: 0 0 6px rgba(255, 209, 102, 0.4); }
        ::-webkit-scrollbar-thumb:hover { background: #ffe399; box-shadow: 0 0 10px rgba(255, 209, 102, 0.8); }
        * { scrollbar-width: thin; scrollbar-color: #ffd166 #121215; }

        body {
            font-family: 'Courier New', Courier, monospace;
            background-color: var(--bg-color);
            color: var(--text-main);
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .container { width: 100%; max-width: 1200px; }

        .header {
            display: flex; justify-content: space-between; align-items: center;
            flex-wrap: wrap; gap: 15px; /* Разрешаем перенос кнопок вниз, если не хватает места */
            background: var(--panel-bg); padding: 15px 25px; border-radius: 6px;
            border: 1px solid #333; margin-bottom: 20px;
        }

        .char-info { 
            flex: 1 1 300px; /* Делаем блок с текстом эластичным */
        }

        .char-info h1 {
            margin: 0; font-size: 26px; color: var(--accent); cursor: text;
            border-bottom: 1px dashed transparent; transition: 0.2s; outline: none;
        }
        .char-info h1:hover, .char-info h1:focus { border-bottom: 1px dashed var(--accent); }
        
        .stats-row {
            margin: 8px 0 0 0; color: var(--text-muted); font-size: 14px;
            display: flex; flex-wrap: wrap; align-items: center; gap: 8px 0; /* Отступ между строками при переносе */
        }
        .stat-item {
            white-space: nowrap; /* Запрещает разрывать текст внутри блока */
            display: inline-flex; align-items: center;
        }
        .stat-item.gold-stat {
            flex: 0 0 auto; flex-wrap: nowrap; gap: 1ch;
            white-space: nowrap; overflow-wrap: normal; font-weight: bold;
        }
        .gold-stat .gold-coin {
            display: block; width: 11px; height: 10px; flex: 0 0 11px;
            image-rendering: pixelated;
        }
        .gold-stat #player-gold { flex: 0 0 auto; white-space: nowrap; }
        .divider {
            margin: 0 8px; color: #444; /* Цвет палочек-разделителей */
        }

        /* Компактный индикатор HP */
        .hp-badge {
            display: inline-block;
            vertical-align: middle;
            user-select: none;
            transition: 0.3s;
            margin-right: 8px;
            border: none;
            background: transparent;
            padding: 0;
            box-shadow: none;
            color: #ff5555;
            font-weight: bold;
            font-size: 14px;
            letter-spacing: 0px;
        }

        /* Питомец в информационной строке */
        #pet-info-wrapper {
            position: relative;
            align-items: center;
            align-self: center;
            gap: 4px;
            line-height: 1.35;
        }
        .active-pet-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex: 0 0 44px;
            width: 44px;
            height: 44px;
            padding: 0;
            border: 0;
            border-radius: 6px;
            background: transparent;
            color: inherit;
            font-family: inherit;
            font-size: 34px;
            line-height: 1;
            appearance: none;
            -webkit-appearance: none;
            cursor: pointer;
            user-select: none;
            touch-action: manipulation;
            -webkit-tap-highlight-color: transparent;
        }
        .active-pet-icon:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: 2px;
        }
        .pet-glyph {
            display: block;
            pointer-events: none;
            animation: petFloat 4s ease-in-out infinite;
        }

        /* Облачко открывается и мышью, и нажатием на сенсорном экране. */
        .pet-speech {
            position: absolute;
            bottom: calc(100% + 6px);
            left: 0;
            width: max-content;
            max-width: min(240px, calc(100vw - 58px));
            box-sizing: border-box;
            background: #1e1b18;
            border: 1px solid #8c6f48;
            color: #ffd166;
            padding: 7px 10px;
            border-radius: 4px;
            font-size: 11px;
            line-height: 1.4;
            font-weight: normal;
            white-space: normal;
            overflow-wrap: anywhere;
            pointer-events: none;
            box-shadow: 0 4px 10px rgba(0,0,0,0.8);
            font-family: 'Courier New', monospace;
            z-index: 1000;
        }
        .pet-speech[hidden] { display: none; }
        .pet-speech-phrase, .pet-speech-time { display: block; }
        .pet-speech-time { margin-top: 4px; color: #bfb6a6; font-size: 10px; }

        @keyframes petFloat {
            0%, 100% { transform: translateY(2px); }
            50% { transform: translateY(-2px); }
        }
        @media (prefers-reduced-motion: reduce) {
            .pet-glyph { animation: none; }
        }

        /* --- КНОПКИ УПРАВЛЕНИЯ И ВСПЛЫВАЮЩИЕ НАДПИСИ --- */
        .controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end;}
        .controls button {
            position: relative;
            background: #2a2a2a; color: white; border: 1px solid #444;
            width: 42px; height: 42px; padding: 0; cursor: pointer; border-radius: 4px;
            font-family: inherit; transition: 0.2s;
            display: inline-flex; align-items: center; justify-content: center;
        }
        .controls button:hover { background: #444; border-color: #ffd166; }
        .controls .toolbar-icon {
            width: 31px; height: 31px; object-fit: contain; display: block;
            image-rendering: pixelated; user-select: none; pointer-events: none;
            filter: drop-shadow(0 1px 2px rgba(0,0,0,0.7));
        }
        /* Оптическая балансировка: вытянутые иконки могут быть крупнее,
           плотные формы чуть меньше — визуальный вес получается одинаковее. */
        .controls button[data-tooltip="Реликварий"] .toolbar-icon,
        .controls button[data-tooltip="Летопись"] .toolbar-icon { width: 34px; height: 34px; }
        .controls button[data-tooltip="Восстановить"] .toolbar-icon { width: 32px; height: 32px; }
        .controls button[data-tooltip="Настройки"] .toolbar-icon { width: 30px; height: 30px; }
        .controls button[data-tooltip="Достижения"] .toolbar-icon { width: 32px; height: 32px; }
        .controls button[data-tooltip="Резервная копия"] .toolbar-icon { width: 27px; height: 27px; }
        .controls button[data-tooltip="Бестиарий"] .toolbar-icon { width: 29px; height: 29px; }
        .controls button[data-tooltip="Трофеи"] .toolbar-icon { width: 30px; height: 30px; }
        .modal-title-row {
            display: inline-flex;
            align-items: center;
            gap: 10px;
            margin: 0;
            color: #d4af37;
            border: none !important;
        }
        .modal-title-icon {
            width: 27px;
            height: 27px;
            object-fit: contain;
            display: block;
            image-rendering: pixelated;
            flex: 0 0 auto;
            filter: drop-shadow(0 1px 2px rgba(0,0,0,0.7));
        }
        
        .controls button[data-tooltip]:hover::after {
            content: attr(data-tooltip);
            position: absolute; top: 125%; left: 50%; transform: translateX(-50%);
            background: #191714; border: 1px solid #8c6f48; color: #ffd166;
            font-size: 12px; font-weight: bold; padding: 6px 12px; white-space: nowrap;
            border-radius: 4px; box-shadow: 0 4px 15px rgba(0,0,0,0.9);
            z-index: 100000; pointer-events: none;
            animation: tooltipFadeIn 0.2s ease-out forwards;
        }
        @keyframes tooltipFadeIn {
            from { opacity: 0; transform: translate(-50%, -5px); }
            to { opacity: 1; transform: translate(-50%, 0); }
        }

        .skills-header { margin: 0 0 10px 0; font-size: 14px; color: var(--text-muted); }
        .skills-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 25px; }
        .skill-card {
            background: var(--panel-bg); padding: 12px; border-radius: 6px; border: 1px solid #333;
            cursor: pointer; transition: 0.2s; display: flex; flex-direction: column; justify-content: space-between; min-height: 60px;
        }
        .skill-card:hover { border-color: #666; }
        .skill-card.selected { border-color: var(--skill-color); box-shadow: 0 0 8px inset rgba(0,0,0,0.5); background: #111; }
        .skill-name { font-weight: bold; font-size: 14px; display: flex; align-items: center; gap: 8px; }
        .skill-level { font-size: 12px; color: var(--text-muted); text-align: right; margin-top: 5px;}

        /* --- СЧЕТЧИК СТРИКА (ОГОНЬ) --- */
        .streak-box {
            margin-left: 10px; padding: 3px 8px; border-radius: 6px; background: #111;
            border: 1px solid #333; font-weight: bold; font-size: 13px; transition: 0.3s;
            user-select: none; display: inline-block;
        }
        .streak-fire { color: #ff7300; text-shadow: 0 0 8px rgba(255, 115, 0, 0.6); }
        .streak-gold { color: #ffd700; border-color: #d4af37; text-shadow: 0 0 10px rgba(255, 215, 0, 0.8); box-shadow: inset 0 0 5px rgba(212, 175, 55, 0.2); }
        .streak-blue {
            color: #00f0ff; border-color: #00f0ff; text-shadow: 0 0 12px rgba(0, 240, 255, 0.9);
            box-shadow: inset 0 0 8px rgba(0, 240, 255, 0.3); animation: blueFlame 1.5s infinite alternate;
        }

        .year-grid-container { background: var(--panel-bg); padding: 25px; border-radius: 6px; border: 1px solid #333; }
        .grid-header { margin: 0 0 15px 0; display: flex; justify-content: space-between; align-items: center; }
        .season-controls { display: flex; align-items: center; gap: 6px; }
        .season-btn {
            background: #2a2a2a; color: #ffd166; border: 1px solid #444; padding: 6px 12px;
            cursor: pointer; border-radius: 4px; font-family: inherit; font-size: 12px; transition: 0.2s;
        }
        .season-btn:hover { background: #444; border-color: #ffd166; }
        .season-label { color: var(--accent); font-weight: bold; font-size: 14px; letter-spacing: 1px; padding: 0 4px; user-select: none; }

        .grid { display: grid; grid-template-columns: repeat(53, 1fr); gap: 5px; }
        .day {
            aspect-ratio: 1; background: var(--grid-bg); border-radius: 3px;
            cursor: pointer; position: relative; border: 1px solid #111;
        }
        .day:hover { border-color: #fff; z-index: 2; transform: scale(1.2); }
        .day.future { opacity: 0.6; }
        .day.future:hover { border-color: var(--accent); }

        /* Сегодня ещё не сохранён: заметный красный маяк.
           После первого сохранения дня класс исчезает. */
        .day.today-pending {
            background: #6f1d2a !important;
            border-color: #ff596b !important;
            box-shadow: 0 0 8px rgba(255, 70, 90, 0.9), inset 0 0 5px rgba(255, 120, 130, 0.35);
            animation: todayPendingPulse 1.9s ease-in-out infinite;
            z-index: 1;
        }
        @keyframes todayPendingPulse {
            0%, 100% { box-shadow: 0 0 5px rgba(255, 70, 90, 0.65), inset 0 0 4px rgba(255, 120, 130, 0.25); }
            50% { box-shadow: 0 0 11px rgba(255, 70, 90, 1), inset 0 0 7px rgba(255, 120, 130, 0.45); }
        }

        .day.perfect-day { border-color: #ffd166 !important; animation: perfectPulse 2.4s infinite ease-in-out; z-index: 1; }
        .day.perfect-day::before {
            content: '👑'; position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
            font-size: 8px; line-height: 1; pointer-events: none; filter: drop-shadow(0 1px 2px #000); z-index: 5;
        }
        @keyframes perfectPulse {
            0%, 100% { box-shadow: 0 0 5px rgba(255, 209, 102, 0.5), inset 0 0 3px rgba(255, 215, 0, 0.4); }
            50% { box-shadow: 0 0 12px rgba(255, 209, 102, 0.95), inset 0 0 6px rgba(255, 215, 0, 0.8); }
        }
        
        .day.has-note::after { content: ''; position: absolute; bottom: 2px; right: 2px; width: 4px; height: 4px; background: #fff; border-radius: 50%; }
        .day.has-capsule::after { content: '🔒'; position: absolute; font-size: 8px; top: 50%; left: 50%; transform: translate(-50%, -50%); }

        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.88); display: none; justify-content: center; align-items: center; z-index: 100;
        }
        .modal { background: #1a1a1a; padding: 25px; border-radius: 6px; border: 1px solid var(--accent); width: 100%; max-width: 450px; box-sizing: border-box;}
        .modal h2 { margin-top: 0; color: var(--accent); border-bottom: 1px solid #333; padding-bottom: 10px; }
        
        .habit-list { margin: 15px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
        .habit-item { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
        
        input[type="text"], input[type="number"], textarea {
            width: 100%; background: #000; color: white; border: 1px solid #444; padding: 10px; font-family: inherit; box-sizing: border-box; border-radius: 4px;
        }
        textarea { height: 90px; resize: none; margin-top: 10px; }
        input[type="range"] { width: 100%; margin-top: 5px; accent-color: var(--accent); cursor: pointer; }

        .reminder-settings {
            margin-top: 18px; padding: 14px; border: 1px solid #3a3425; border-radius: 8px; background: #15130e;
        }
        .reminder-toggle-row { display:flex; align-items:center; gap:10px; cursor:pointer; font-size:14px; }
        .reminder-toggle-row input { width:18px; height:18px; accent-color:var(--accent); flex:0 0 auto; }
        .reminder-time-row { margin-top:12px; display:flex; align-items:center; justify-content:space-between; gap:12px; }
        .reminder-time-button {
            background:#090909; color:#f4f1e8; border:1px solid #5a4b22; border-radius:8px; padding:9px 14px;
            font-family:inherit; font-size:18px; min-width:126px; min-height:44px; cursor:pointer; letter-spacing:1px;
            box-shadow:inset 0 0 0 1px rgba(255,209,102,.04);
        }
        .reminder-time-button:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
        .reminder-time-button:active { transform:translateY(1px); }

        .reminder-wheel-overlay {
            position:fixed; inset:0; display:none; align-items:center; justify-content:center; padding:18px; box-sizing:border-box;
            background:rgba(0,0,0,.82); z-index:700000; overscroll-behavior:contain;
        }
        .reminder-wheel-dialog {
            width:min(360px, 100%); background:#151612; border:1px solid var(--accent); border-radius:14px; padding:18px;
            box-sizing:border-box; box-shadow:0 18px 55px rgba(0,0,0,.75);
        }
        .reminder-wheel-title { color:var(--accent); font-size:18px; font-weight:bold; text-align:center; margin-bottom:4px; }
        .reminder-wheel-subtitle { color:#777; font-size:11px; line-height:1.45; text-align:center; margin-bottom:14px; }
        .reminder-wheel-labels {
            display:grid; grid-template-columns:104px 104px; justify-content:center; gap:18px;
            margin:10px auto 5px; color:#777; font-size:10px; text-align:center;
            text-transform:uppercase; letter-spacing:1.5px;
        }
        .reminder-wheel-wrap {
            position:relative; display:grid; grid-template-columns:104px 104px; justify-content:center; gap:18px;
            width:244px; max-width:100%; height:220px; margin:0 auto; overflow:hidden; border-radius:10px;
        }
        .reminder-wheel-selection {
            position:absolute; left:5px; right:5px; top:88px; height:44px; pointer-events:none; z-index:3;
            border-top:1px solid rgba(255,209,102,.62); border-bottom:1px solid rgba(255,209,102,.62);
            background:rgba(255,209,102,.055); border-radius:7px;
        }
        .reminder-wheel-column {
            height:220px; overflow-y:auto; padding:88px 0; box-sizing:border-box; scroll-snap-type:y mandatory;
            scroll-padding-block:88px; overscroll-behavior:contain; -webkit-overflow-scrolling:touch; scrollbar-width:none;
            mask-image:linear-gradient(to bottom, transparent 0%, black 24%, black 76%, transparent 100%);
            -webkit-mask-image:linear-gradient(to bottom, transparent 0%, black 24%, black 76%, transparent 100%);
        }
        .reminder-wheel-column::-webkit-scrollbar { display:none; }
        .reminder-wheel-option {
            display:flex; align-items:center; justify-content:center; width:100%; height:44px; padding:0; margin:0; border:0;
            background:transparent; color:#777; font-family:inherit; font-size:20px; cursor:pointer; scroll-snap-align:center; scroll-snap-stop:always;
            transition:color .12s ease, font-size .12s ease, opacity .12s ease; opacity:.72;
        }
        .reminder-wheel-option.is-selected { color:#f6d35f; font-size:27px; font-weight:bold; opacity:1; text-shadow:0 0 12px rgba(255,209,102,.16); }
        .reminder-wheel-actions { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:14px; }
        .reminder-wheel-action {
            min-height:46px; border-radius:8px; border:1px solid #444; background:#292929; color:#ddd; font-family:inherit;
            font-weight:bold; font-size:14px; cursor:pointer;
        }
        .reminder-wheel-action.primary { background:var(--accent); color:#111; border-color:var(--accent); }
        .reminder-status { margin-top:10px; color:#888; font-size:11px; line-height:1.45; }
        .reminder-status.ok { color:#7fdc9a; }
        .reminder-status.warn { color:#ffd166; }
        .reminder-status.error { color:#ff8888; }
        
        .modal-btn {
            background: var(--accent); color: black; border: none; padding: 12px; width: 100%;
            margin-top: 20px; font-weight: bold; cursor: pointer; border-radius: 4px; font-family: inherit;
        }
        .modal-btn:hover { filter: brightness(1.1); }
        .close-btn { background: #333; color: white; margin-top: 10px; }
        .capsule-warning { color: var(--accent); font-size: 12px; margin-bottom: 10px; }

        .day-locked-banner {
            display: none; background: #2a1111; color: #ff8888; border: 1px solid #ff4444;
            padding: 8px 12px; border-radius: 4px; font-size: 12px; margin-bottom: 12px; text-align: center;
        }

        @media (max-width: 600px) {
            .grid { display: grid !important; grid-template-columns: repeat(auto-fit, minmax(20px, 1fr)) !important; gap: 4px !important; overflow-x: auto; }
        }

        .xp-bar-container { width: 100%; height: 6px; background-color: #000; border: 1px solid #333; border-radius: 3px; margin-top: 10px; position: relative; overflow: hidden; }
        .xp-bar-fill { height: 100%; width: 0%; transition: width 0.5s ease-out; background-color: var(--accent); box-shadow: inset 0 1px 2px rgba(255,255,255,0.2); }

        /* Тосты Level Up, HP и Босса */
        #levelup-toast-container {
            position: fixed; bottom: 25px; left: 25px; display: flex;
            flex-direction: column-reverse; gap: 10px; z-index: 99999; pointer-events: none;
        }
        .osrs-toast {
            background: #1c150c; border: 2px solid #f5c542; border-radius: 6px; padding: 10px 16px; color: #ffd700;
            box-shadow: 0 4px 15px rgba(0,0,0,0.8), 0 0 10px rgba(245, 197, 66, 0.4);
            display: flex; align-items: center; gap: 10px; font-family: inherit; font-size: 0.95rem;
            animation: toastSlideIn 0.3s ease-out forwards; transition: opacity 0.5s ease, transform 0.5s ease;
        }
        .osrs-toast.hide { opacity: 0; transform: translateY(15px) scale(0.9); }
        @keyframes toastSlideIn { 0% { transform: translateX(-50px); opacity: 0; } 100% { transform: translateX(0); opacity: 1; } }
        
        .skill-card-levelup { animation: skillGlowPulse 1.8s ease-out !important; }
        @keyframes skillGlowPulse { 0% { box-shadow: 0 0 0 rgba(245, 197, 66, 0); border-color: inherit; } 30% { box-shadow: 0 0 25px rgba(245, 197, 66, 0.9); border-color: #ffd700; transform: scale(1.02); } 100% { box-shadow: 0 0 0 rgba(245, 197, 66, 0); border-color: inherit; transform: scale(1); } }

        /* Стили плашек Босса и HP */
        .toast-dmg {
            background: #1a0505; border: 1px solid #ff4444; border-radius: 4px; padding: 6px 12px; 
            color: #ff5555; font-weight: bold; font-family: monospace; box-shadow: 0 0 10px rgba(255,0,0,0.5); 
            font-size: 14px; animation: toastSlideIn 0.2s ease-out forwards; max-width: fit-content;
            transition: opacity 0.3s ease;
        }
        .toast-heal { background: #051a05; border: 1px solid #44ff44; color: #55ff55; box-shadow: 0 0 10px rgba(0,255,0,0.5); }
        .toast-phrase {
            background: #240a0a; border: 2px solid #ff3333; border-radius: 6px; padding: 12px 18px; 
            color: #ffcccc; display: flex; align-items: center; gap: 12px; font-family: 'Courier New', monospace; 
            animation: toastSlideIn 0.3s ease-out forwards; max-width: 350px; transition: opacity 0.3s ease;
        }
        .boss-toast-icon { font-size: 32px; line-height: 1; filter: drop-shadow(0 2px 4px #000); }

        /* Окно витрины, Достижений и Бестиария */
        .osrs-modal-window, .hall-modal {
            background: #0f0f11 !important; border: 2px solid #ffd166 !important; border-radius: 12px;
            width: 95vw; max-width: 980px !important; height: 85vh !important; max-height: 85vh !important;
            overflow-y: auto !important; overflow-x: hidden !important; padding: 24px 28px !important;
            box-sizing: border-box; box-shadow: 0 0 45px rgba(0, 0, 0, 0.95);
        }
        .osrs-modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #2a2a2e; padding-bottom: 12px; margin-bottom: 22px; }
        .osrs-modal-header h2 { color: #ffd166; font-size: 21px; letter-spacing: 1.5px; margin: 0; }
        .osrs-close-x { background: transparent; border: 1px solid #444; color: #aaa; font-size: 16px; width: 34px; height: 34px; border-radius: 6px; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center;}
        .osrs-close-x:hover { color: #fff; border-color: #ffd166; }

        .max-cape-section { width: 100%; background: radial-gradient(circle at center, #261616 0%, #141416 100%); border: 2px solid #ffd166; border-radius: 12px; padding: 22px; margin-bottom: 25px; display: flex; flex-direction: column; align-items: center; box-shadow: 0 0 25px rgba(212, 175, 55, 0.2); text-align: center; box-sizing: border-box; }
        .max-badge { background: #d4af37; color: #000; font-weight: bold; font-size: 11px; padding: 4px 14px; border-radius: 20px; margin-bottom: 15px; letter-spacing: 1px; }
        .capes-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; width: 100%; box-sizing: border-box; }
        @media (max-width: 820px) { .capes-grid { grid-template-columns: repeat(2, 1fr); } }

        .cape-card { background: #17171a; border: 1px solid #333; border-radius: 10px; padding: 16px 10px; display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease; }
        .cape-card:hover { transform: translateY(-4px); border-color: #ffd166; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6); }
        .cape-svg-container { position: relative; display: flex; justify-content: center; align-items: center; }
        .cape-svg { width: 110px; height: 145px; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5)); }
        .max-cape-svg { width: 150px; height: 195px; filter: drop-shadow(0 0 18px rgba(255, 60, 60, 0.4)); }
        .cape-name { font-weight: bold; font-size: 14px; margin-top: 10px; color: #fff; }
        .cape-desc { font-size: 11px; color: #888; margin-top: 3px; }
        .cape-status-lbl { font-size: 11px; margin-top: 8px; font-weight: bold; }
        .locked .cape-svg, .locked .max-cape-svg { filter: grayscale(100%) brightness(35%) contrast(120%) !important; }
        .locked .cape-name { color: #666; }
        .locked .cape-card { border-color: #242424; }
        .lock-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 26px; filter: drop-shadow(0 2px 5px #000); pointer-events: none; display: none; }
        .locked .lock-icon { display: block; }

        .hall-modal { display: flex; flex-direction: column; overflow: hidden !important; }
        #trophiesList { flex: 1; overflow-y: auto !important; overflow-x: hidden !important; padding: 10px 14px 10px 0; margin-bottom: 12px; }
        .trophy-row { display: flex; align-items: center; justify-content: space-between; background: #19191d; border: 1px solid #2f2f35; padding: 12px 22px !important; border-radius: 10px; margin-bottom: 10px; position: relative; }
        .trophy-row:hover { border-color: #ffd166; z-index: 9999; }
        .trophy-skill-label { font-size: 17px !important; font-weight: bold; color: #ffffff; display: flex; align-items: center; gap: 12px; }
        .trophy-stages { display: flex; gap: 18px !important; align-items: center; }
        .trophy-badge { position: relative; width: 46px !important; height: 46px !important; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 23px !important; cursor: pointer; user-select: none; transition: transform 0.15s ease, filter 0.15s ease; }
        .trophy-badge:hover { transform: scale(1.15); }
        .badge-locked { background: #1b1b20 !important; border: 2px dashed #4a4a55 !important; opacity: 0.55 !important; filter: grayscale(80%) brightness(85%) !important; }
        .badge-wood { background: radial-gradient(circle, #6b411c 0%, #2e1806 100%); border: 2px solid #a46932; box-shadow: inset 0 0 5px #1a0d03; }
        .badge-iron { background: radial-gradient(circle, #7e8891 0%, #2f3438 100%); border: 2px solid #a8b4c4; box-shadow: inset 0 0 5px #111; }
        .badge-silver { background: radial-gradient(circle, #ffffff 0%, #7e878f 100%); border: 2px solid #ffffff; box-shadow: 0 0 12px rgba(255, 255, 255, 0.85); }
        .badge-gold { background: radial-gradient(circle, #fff04d 0%, #ff8c00 100%); border: 2px solid #fff585; box-shadow: 0 0 16px rgba(255, 215, 0, 0.9); }
        .badge-mythril { background: radial-gradient(circle, #33f3ff 0%, #0056b3 100%); border: 2px solid #99f9ff; box-shadow: 0 0 18px rgba(0, 240, 255, 0.95); }

        .trophy-badge .tooltip-text { display: none; position: absolute; bottom: 125%; left: 50%; transform: translateX(-50%); background: #09090b; color: #ffd166; text-align: center; padding: 6px 12px !important; border-radius: 6px; border: 1px solid #ffd166; font-size: 12px !important; font-weight: bold; white-space: nowrap; z-index: 10000; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.95); pointer-events: none; }
        .trophy-row.first-row .tooltip-text { bottom: auto !important; top: 125% !important; }
        .trophy-badge.align-right .tooltip-text { left: auto; right: 0; transform: none; }
        .trophy-badge:hover .tooltip-text { display: block; }

        /* Бестиарий */
        .bestiary-grid { 
            display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); 
            gap: 15px; overflow-y: auto; padding: 10px 5px; flex: 1; margin-top: 10px; 
            justify-content: center; justify-items: center; align-content: start;
        }
        .boss-card { 
            background: #1a1a1d; border: 1px solid #333; border-radius: 8px; 
            padding: 15px 10px; text-align: center; position: relative; transition: 0.3s; 
            margin: 0 auto; max-width: 180px; width: 100%; box-sizing: border-box;
        }
        .boss-card.defeated { 
            border-color: #ffd166; 
            background: linear-gradient(145deg, #2a2211 0%, #1a1a1d 100%);
            box-shadow: 0 0 15px rgba(212, 175, 55, 0.3), inset 0 0 20px rgba(212, 175, 55, 0.1);
        }
        .boss-card.defeated .boss-card-icon {
            filter: drop-shadow(0 0 12px rgba(255, 209, 102, 0.6));
            transform: scale(1.05);
        }
        .boss-card.current { border-color: #ff4444; box-shadow: 0 0 15px rgba(255,0,0,0.2); }
        .boss-card.locked { opacity: 0.5; filter: grayscale(1) brightness(0.3); border-color: #111; }
        .boss-card-icon { 
            font-size: 55px; margin-bottom: 12px; line-height: 1.1; 
        }
        .boss-card-name { font-weight: bold; font-size: 13px; color: #fff; margin-bottom: 5px; }
        .boss-card-status { font-size: 11px; font-family: monospace; }
        .card-hp-bg { width: 100%; height: 6px; background: #333; border-radius: 3px; overflow: hidden; margin-top: 8px; }
        .card-hp-fill { height: 100%; background: #ff4444; transition: 0.3s; }

        /* --- Стили для Летописи --- */
        .chronicle-theme {
            background: #1a1a1a;
            border: 2px solid #d4af37;
            box-shadow: 0 0 30px rgba(212, 175, 55, 0.15);
            max-height: 85vh; /* Жесткое ограничение: не больше 85% экрана */
            display: flex;
            flex-direction: column;
        }
        
        .chronicle-scroll-area {
            flex: 1; /* Занимает всё доступное место внутри модалки */
            overflow-y: auto;
            overflow-x: hidden;
            padding: 30px 15px; 
            margin: -10px 0; 
            mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 90%, transparent 100%);
            -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 90%, transparent 100%);
        }

        .chronicle-scroll-area::-webkit-scrollbar {
            width: 6px;
        }
        .chronicle-scroll-area::-webkit-scrollbar-thumb {
            background: #d4af37;
            border-radius: 3px;
        }

        /* Единый стиль "старых чернил" для всех записей */
        .chronicle-entry {
            margin-bottom: 25px;
            line-height: 1.6;
            font-size: 15px;
            font-family: 'Courier New', Courier, monospace;
            transition: 0.3s;
            text-align: left;
            word-break: break-word;
            overflow-wrap: break-word;
            white-space: pre-wrap; /* Заставляет браузер уважать переносы строк */
            
            /* Дизайн: серый цвет, курсив, полоска слева */
            color: #b3b3b3; 
            border-left: 2px solid #555;
            padding-left: 12px;
            font-style: italic;
        }
        
/* --- СТИЛЬ ЗОЛОТОЙ КИСТИ --- */
        .entry-golden {
            color: #ffd166 !important;
            border-left: 2px solid #ffd166 !important;
            text-shadow: 0 0 8px rgba(255, 209, 102, 0.2);
        }
        
        /* Чтобы дата в золотой записи тоже слегка отливала золотом, а не была серой */
        .entry-golden .chronicle-date {
            color: #e3bc52 !important; 
        }

        .chronicle-date {
            display: block;
            font-size: 12px;
            color: #888;
            font-family: sans-serif;
            margin-bottom: 6px;
            letter-spacing: 1px;
            font-weight: bold;
        }

        /* Пустые классы, чтобы старые скрипты ничего не перекрашивали */
        .entry-sealed, .entry-laying, .entry-opening, .entry-destroyed {}

        /* --- Стили карточек Реликвария --- */
        .relic-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 15px;
            padding: 10px 0;
            width: 100%;
        }
        .relic-card {
            background: #19191d;
            border: 1px solid #333;
            border-radius: 8px;
            padding: 18px;
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
            transition: 0.2s;
        }
        .relic-card:hover {
            border-color: #ffd166;
            box-shadow: 0 0 15px rgba(255, 209, 102, 0.15);
        }
        .relic-icon { 
            font-size: 44px; 
            margin-bottom: 10px; 
            filter: drop-shadow(0 2px 4px #000);
            font-style: normal; /* Выпрямляет эмодзи */
            display: inline-block;
        }
        .relic-name { font-size: 15px; font-weight: bold; color: #ffd166; margin-bottom: 6px; }
        .relic-desc { font-size: 12px; color: #aaa; margin-bottom: 16px; line-height: 1.4; flex-grow: 1; }
        .relic-btn {
            background: #2a2a2a;
            color: #ffd700;
            border: 1px solid #ffd166;
            padding: 8px 16px;
            border-radius: 4px;
            font-family: inherit;
            font-size: 13px;
            font-weight: bold;
            cursor: pointer;
            transition: 0.2s;
            width: 100%;
        }
        .relic-btn:hover { background: #ffd166; color: #000; }
        .relic-btn:disabled { opacity: 0.4; cursor: not-allowed; border-color: #555; color: #888; background: #1a1a1a; }

/* --- РЕЖИМ АСКЕТИЗМА --- */
        body.ascetic-mode .stats-row { display: none !important; }
        
        body.ascetic-mode button[data-tooltip="Реликварий"],
        body.ascetic-mode button[data-tooltip="Бестиарий"],
        body.ascetic-mode button[data-tooltip="Трофеи"],
        body.ascetic-mode button[data-tooltip="Достижения"] { display: none !important; }
        
        body.ascetic-mode .skill-level, 
        body.ascetic-mode .xp-bar-container { display: none !important; }
        
        body.ascetic-mode .skill-card { justify-content: center !important; min-height: 45px !important; border-color: #333 !important; background: #111 !important; box-shadow: none !important;}
        body.ascetic-mode .skill-card.selected { border-color: #888 !important; }
        body.ascetic-mode .skill-name { font-size: 16px !important; margin: 0 !important; color: #888 !important; }
        
        body.ascetic-mode #levelup-toast-container { display: none !important; }


        /* =========================================================
           MOBILE / TOUCH LAYOUT v3
           Keeps desktop layout intact, but gives phones a dedicated UI.
           ========================================================= */
        html { width: 100%; min-height: 100%; background: var(--bg-color); }
        body { box-sizing: border-box; min-height: 100%; }
        button, input, textarea { touch-action: manipulation; }

        /* A modal must behave like a real screen on iPhone: no page movement behind it. */
        body.modal-open {
            position: fixed !important;
            left: 0;
            right: 0;
            width: 100%;
            overflow: hidden !important;
        }

        .modal-overlay {
            inset: 0;
            width: auto;
            height: 100dvh;
            box-sizing: border-box;
            z-index: 500000;
            overscroll-behavior: contain;
        }

        .modal,
        .osrs-modal-window,
        .hall-modal {
            overscroll-behavior: contain;
            -webkit-overflow-scrolling: touch;
        }

        .rank-stages-header {
            display: grid !important;
            grid-template-columns: repeat(5, minmax(0, 1fr));
            gap: 8px;
        }

        .class-stat { gap: 6px; }

        .radar-canvas-wrap {
            position: relative;
            width: 100%;
            height: 350px;
            margin-bottom: 16px;
            overflow: hidden;
        }
        #radarChart { display: block; width: 100%; height: 100%; }

        @media (max-width: 700px) {
            body {
                padding-top: max(12px, env(safe-area-inset-top));
                padding-right: max(12px, env(safe-area-inset-right));
                padding-bottom: max(18px, env(safe-area-inset-bottom));
                padding-left: max(12px, env(safe-area-inset-left));
                overflow-x: hidden;
            }

            .container { max-width: none; min-width: 0; }

            .header {
                padding: 16px;
                gap: 14px;
                border-radius: 10px;
                align-items: stretch;
            }
            .char-info { flex: 1 1 100%; min-width: 0; }
            .char-info h1 { font-size: 24px; line-height: 1.15; overflow-wrap: anywhere; }

            .stats-row {
                display: grid;
                grid-template-columns: repeat(2, minmax(0, 1fr));
                gap: 9px 14px;
                margin-top: 12px;
                font-size: 13px;
                line-height: 1.35;
            }
            .stats-row .divider { display: none !important; }
            .stat-item {
                min-width: 0;
                white-space: normal;
                overflow-wrap: anywhere;
                align-items: center;
            }
            .stat-item.gold-stat { grid-column: 1; grid-row: 3; justify-self: start; }
            #pet-info-wrapper {
                grid-column: 1;
                grid-row: 4;
                justify-self: start;
                min-height: 44px;
                color: #aaa;
                white-space: nowrap;
            }
            #pet-info-wrapper .divider { display: none !important; }
            #streak-counter {
                grid-column: 2;
                grid-row: 3;
                margin-left: 0;
                justify-self: end;
                align-self: center;
            }
            .stats-row.has-active-pet #streak-counter { grid-row: 4; }
            .hp-badge { font-size: 13px; }

            #modal-radar .modal {
                width: min(94vw, 430px);
                max-width: 430px !important;
                padding: 18px 14px;
            }
            #modal-radar .modal h2 {
                font-size: 20px;
                line-height: 1.2;
                margin-bottom: 10px;
            }
            #modal-radar .modal > p {
                font-size: 12px !important;
                margin-bottom: 8px !important;
            }
            #modal-radar .radar-canvas-wrap {
                height: 300px;
                margin: 0 auto 10px;
            }
            #radar-class-desc {
                font-size: 14px !important;
                line-height: 1.45;
                margin-bottom: 12px !important;
            }

            .controls {
                width: 100%;
                display: grid;
                grid-template-columns: repeat(4, minmax(0, 1fr));
                gap: 8px;
            }
            .controls button {
                width: 100%;
                min-width: 0;
                min-height: 52px;
                padding: 0;
                border-radius: 8px;
                font-size: 23px;
            }
            .controls .toolbar-icon { width: 37px; height: 37px; }
            .controls button[data-tooltip="Реликварий"] .toolbar-icon,
            .controls button[data-tooltip="Летопись"] .toolbar-icon { width: 41px; height: 41px; }
            .controls button[data-tooltip="Восстановить"] .toolbar-icon { width: 38px; height: 38px; }
            .controls button[data-tooltip="Настройки"] .toolbar-icon { width: 34px; height: 34px; }
            .controls button[data-tooltip="Достижения"] .toolbar-icon { width: 38px; height: 38px; }
            .controls button[data-tooltip="Резервная копия"] .toolbar-icon { width: 31px; height: 31px; }
            .controls button[data-tooltip="Бестиарий"] .toolbar-icon { width: 33px; height: 33px; }
            .controls button[data-tooltip="Трофеи"] .toolbar-icon { width: 35px; height: 35px; }

            .skills-header {
                margin: 0 2px 12px;
                font-size: 13px;
                line-height: 1.5;
            }
            .skills-grid {
                grid-template-columns: repeat(2, minmax(0, 1fr));
                gap: 10px;
                margin-bottom: 18px;
            }
            .skill-card {
                min-width: 0;
                min-height: 108px;
                padding: 12px;
                border-radius: 8px;
            }
            .skill-name {
                min-width: 0;
                font-size: 15px;
                line-height: 1.3;
                align-items: flex-start;
                overflow-wrap: anywhere;
            }
            .skill-level { font-size: 12px; line-height: 1.35; }
            .xp-bar-container { margin-top: 8px; }

            .year-grid-container {
                padding: 16px 12px 18px;
                border-radius: 10px;
                overflow: hidden;
            }
            .grid-header {
                display: flex;
                flex-direction: column;
                align-items: stretch;
                gap: 12px;
                margin-bottom: 14px;
            }
            #current-date-header {
                width: 100%;
                font-size: 20px;
                line-height: 1.3;
                text-align: left;
            }
            .season-controls {
                width: 100%;
                display: grid;
                grid-template-columns: 48px minmax(0, 1fr) 48px;
                align-items: center;
                gap: 10px;
            }
            .season-btn {
                min-height: 44px;
                padding: 0;
                font-size: 17px;
                border-radius: 7px;
            }
            .season-label {
                min-width: 0;
                padding: 0;
                text-align: center;
                white-space: nowrap;
                font-size: 15px;
                letter-spacing: .6px;
            }
            .grid {
                width: 100%;
                display: grid !important;
                grid-template-columns: repeat(13, minmax(0, 1fr)) !important;
                gap: 4px !important;
                overflow: visible !important;
            }
            .day { min-width: 0; border-radius: 4px; }
            .day:hover { transform: none; }

            /* Full-screen-feeling modal behaviour on a phone */
            .modal-overlay {
                padding-top: max(10px, env(safe-area-inset-top));
                padding-right: max(10px, env(safe-area-inset-right));
                padding-bottom: max(10px, env(safe-area-inset-bottom));
                padding-left: max(10px, env(safe-area-inset-left));
                justify-content: center;
                align-items: center;
                overflow: hidden;
                background: rgba(0,0,0,.93);
            }
            .modal {
                width: 100%;
                max-width: 560px;
                max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
                padding: 18px 16px;
                overflow-y: auto;
                box-sizing: border-box;
                border-radius: 10px;
            }
            .modal h2 { font-size: 20px; line-height: 1.3; }
            .habit-list { grid-template-columns: 1fr; gap: 11px; }
            .habit-item { font-size: 15px; min-height: 32px; }
            input[type="text"], input[type="number"], textarea { font-size: 16px; }
            .reminder-time-row { align-items:center; }
            .reminder-time-button { font-size:18px; min-width:126px; }
            textarea { min-height: 110px; }
            .modal-btn { min-height: 48px; font-size: 15px; }

            .osrs-modal-window,
            .hall-modal {
                width: 100% !important;
                max-width: 620px !important;
                height: min(88dvh, 760px) !important;
                max-height: min(88dvh, 760px) !important;
                padding: 16px 14px !important;
                border-radius: 12px;
            }
            .osrs-modal-header {
                gap: 12px;
                padding-bottom: 10px;
                margin-bottom: 14px;
                flex-shrink: 0;
            }
            .osrs-modal-header h2 {
                min-width: 0;
                font-size: 18px;
                line-height: 1.35;
                letter-spacing: .6px;
                overflow-wrap: anywhere;
            }
            .osrs-close-x { width: 42px; height: 42px; flex: 0 0 42px; }

            /* Achievements: 5 ranks still fit, but in a clean grid instead of colliding text. */
            .rank-stages-header {
                grid-template-columns: repeat(5, minmax(0, 1fr));
                gap: 4px;
                padding: 0 !important;
                margin-bottom: 10px !important;
                font-size: 9px !important;
                line-height: 1.2;
            }
            .rank-stages-header span { min-width: 0; text-align: center !important; overflow-wrap: anywhere; }
            #trophiesList {
                padding: 2px 0 8px !important;
                margin-bottom: 8px;
            }
            .trophy-row {
                flex-direction: column;
                align-items: stretch;
                gap: 10px;
                padding: 12px !important;
                margin-bottom: 9px;
            }
            .trophy-skill-label {
                width: 100%;
                font-size: 15px !important;
                line-height: 1.3;
                gap: 8px;
            }
            .trophy-stages {
                width: 100%;
                display: grid;
                grid-template-columns: repeat(5, minmax(0, 1fr));
                gap: 5px !important;
            }
            .trophy-badge {
                width: 42px !important;
                height: 42px !important;
                max-width: 100%;
                justify-self: center;
                font-size: 20px !important;
            }

            /* Bestiary */
            .bestiary-grid {
                grid-template-columns: repeat(2, minmax(0, 1fr));
                gap: 10px;
                padding: 6px 0;
            }
            .boss-card {
                width: 100%;
                max-width: none;
                padding: 12px 8px;
            }
            .boss-card-icon { font-size: 46px; }
            .boss-card-name { font-size: 12px; line-height: 1.3; }

            .capes-grid { grid-template-columns: 1fr !important; gap: 12px; }
            .max-cape-section { padding: 16px 10px; }
            .cape-svg { width: 95px; height: 125px; }
            .max-cape-svg { width: 120px; height: 156px; }

            .chronicle-scroll-area {
                padding: 22px 4px;
                mask-image: none;
                -webkit-mask-image: none;
            }
            .chronicle-entry { font-size: 14px; line-height: 1.55; }

            #levelup-toast-container {
                left: max(10px, env(safe-area-inset-left));
                right: max(10px, env(safe-area-inset-right));
                bottom: max(14px, env(safe-area-inset-bottom));
                align-items: stretch;
            }
            .osrs-toast, .toast-phrase, .toast-dmg { max-width: none; box-sizing: border-box; }

            #welcome-overlay {
                box-sizing: border-box;
                padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
                overflow-y: auto;
            }
            #welcome-overlay > div {
                width: 100%;
                max-width: 520px !important;
                padding: 22px 18px !important;
                box-sizing: border-box;
            }
            #welcome-btn-read, #welcome-btn-sure { width: 100% !important; min-height: 48px; }
        }

        @media (hover: none), (pointer: coarse) {
            .controls button[data-tooltip]:hover::after,
            .trophy-badge:hover .tooltip-text { display: none !important; content: none !important; }
            .skill-card:hover, .cape-card:hover, .trophy-badge:hover { transform: none; }
        }


        /* --- РЕЗЕРВНЫЕ КОПИИ --- */
        .backup-intro { color:#aaa; font-size:12px; line-height:1.55; margin:0 0 14px; }
        .backup-card { background:#141417; border:1px solid #34343a; border-radius:9px; padding:14px; margin:12px 0; text-align:left; }
        .backup-card h3 { color:#ffd166; font-size:14px; margin:0 0 7px; }
        .backup-card p { color:#aaa; font-size:11px; line-height:1.5; margin:6px 0 10px; }
        .backup-card .modal-btn { margin-top:7px; }
        .backup-status { color:#8b8b92; font-size:11px; line-height:1.45; margin-top:9px; overflow-wrap:anywhere; }
        .backup-status.ok { color:#7fdc9a; }
        .backup-status.warn { color:#ffd166; }
        .backup-status.error { color:#ff8888; }
        .backup-code-box { width:100%; min-height:116px; resize:none; box-sizing:border-box; background:#08090b; color:#e7d27c; border:1px solid #5b4a17; border-radius:7px; padding:10px; font-family:'Courier New', monospace; font-size:11px; line-height:1.45; word-break:break-all; }
        .backup-code-input { width:100%; min-height:96px; resize:vertical; box-sizing:border-box; background:#09090b; color:#eee; border:1px solid #444; border-radius:7px; padding:10px; font-family:'Courier New', monospace; font-size:12px; line-height:1.45; }
        .backup-password-input { width:100%; box-sizing:border-box; background:#09090b; color:#fff; border:1px solid #444; border-radius:7px; padding:10px; font-family:inherit; font-size:15px; margin:7px 0; }
        .backup-small-note { color:#777; font-size:10px; line-height:1.45; margin-top:8px; }
        @media (max-width: 600px) {
            #modal-backup-save .modal, #modal-backup-restore .modal, #modal-backup-password .modal, #modal-recovery-code .modal { max-width:92vw; }
            .backup-card { padding:12px; }
        }

    