:root {
  color-scheme: light dark;
  --bg: #f4eee2;
  --surface: #ffffff;
  --border: #e3d9c6;
  --text: #2e3440;
  --text-muted: #6b7280;
  --accent: #5e81ac;
  --accent-text: #eceff4;
  --danger: #bf616a;
  --ok: #a3be8c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #2e3440;
    --surface: #3b4252;
    --border: #4c566a;
    --text: #eceff4;
    --text-muted: #d8dee9;
    --accent: #88c0d0;
    --accent-text: #2e3440;
  }
}

:root[data-theme="dark"] {
  --bg: #2e3440; --surface: #3b4252; --border: #4c566a; --text: #eceff4;
  --text-muted: #d8dee9; --accent: #88c0d0; --accent-text: #2e3440;
}

:root[data-theme="light"] {
  --bg: #f4eee2; --surface: #ffffff; --border: #e3d9c6; --text: #2e3440;
  --text-muted: #6b7280; --accent: #5e81ac; --accent-text: #eceff4;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, system-ui, sans-serif; }

.gallery-header { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem; padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.header-side { display: flex; }
.header-side-right { justify-content: flex-end; }
.header-center { justify-self: center; }
.running-badge { font-size: .9rem; color: var(--text-muted); }

.stats-banner { display: flex; flex-wrap: wrap; gap: 1px; background: var(--border); }
.stat { flex: 1 1 calc(50% - 1px); min-width: 0; background: var(--surface); padding: 1rem; display: flex; flex-direction: column; gap: .2rem; }
@media (min-width: 560px) { .stat { flex-basis: 140px; } }
.stat span { font-size: .8rem; color: var(--text-muted); }
.stat strong { font-size: 1.6rem; }
.stat small { color: var(--text-muted); font-size: .8rem; }

.service-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; padding: 1rem; }
.service-card { perspective: 1000px; min-height: 150px; }
.card-flip { position: relative; width: 100%; height: 100%; min-height: 150px; transition: transform .5s; transform-style: preserve-3d; }
.service-card.flipped .card-flip { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; backface-visibility: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; box-sizing: border-box; }
.card-front { display: flex; align-items: center; gap: .6rem; cursor: pointer; pointer-events: auto; }
.service-card.flipped .card-front { pointer-events: none; }
.card-front .service-name { color: var(--text); font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.service-card.running .status-dot { background: var(--ok); }
.flip-btn, .flip-back-btn { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.3rem; width: 40px; height: 40px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.card-back { transform: rotateY(180deg); display: flex; flex-direction: column; gap: .5rem; pointer-events: none; }
.service-card.flipped .card-back { pointer-events: auto; }
.card-back-top { display: flex; justify-content: flex-end; }
.card-back-actions { display: flex; flex-direction: column; gap: .5rem; flex: 1; justify-content: center; }
.card-back .btn-ghost { width: 100%; padding: .6rem; font-size: .85rem; }
.card-back .flip-back-btn { width: 28px; height: 28px; }

.auth { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; gap: 1.25rem; text-align: center; }
.auth h1 { font-size: 1.4rem; font-weight: 600; margin: 0 0 .5rem; }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; }
.btn { width: 100%; font-size: 1.1rem; padding: .9rem 1rem; border-radius: 12px; border: none; background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; }
.btn-ghost { width: 100%; font-size: 1rem; padding: .8rem 1rem; border-radius: 12px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; }
.field { width: 100%; font-size: 1.1rem; padding: .9rem 1rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.field::placeholder { color: var(--text-muted); }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--text-muted); font-size: .85rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-status { min-height: 1.2rem; color: var(--text-muted); font-size: .95rem; }
.auth-back { color: var(--text-muted); text-decoration: none; font-size: .95rem; display: inline-block; margin-top: .5rem; }

.menu-btn { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; }

.settings-page { max-width: 640px; margin: 0 auto; padding: 2rem 1.25rem 3rem; }
.settings-header h1 { font-size: 1.7rem; font-weight: 800; margin: 0 0 .25rem; letter-spacing: -0.02em; }
.settings-sub { color: var(--text-muted); margin: 0 0 2rem; }
.settings-section { margin-bottom: 1.75rem; }
.settings-section h2 { display: flex; align-items: center; gap: .6rem; font-size: 1.05rem; font-weight: 700; margin: 0 0 .75rem; }
.section-icon { width: 32px; height: 32px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.section-icon-danger { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.settings-row-link { display: flex; align-items: center; justify-content: space-between; gap: 1rem; text-decoration: none; color: inherit; }
.row-title { font-weight: 700; margin: 0 0 .15rem; }
.row-desc { color: var(--text-muted); font-size: .85rem; margin: 0; }
.chevron { color: var(--text-muted); font-size: 1.3rem; flex-shrink: 0; }
.btn-danger { width: 100%; padding: .8rem 1rem; border-radius: 14px; border: none; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-weight: 600; cursor: pointer; font-size: 1rem; }

.theme-switcher { display: flex; gap: .5rem; }
.theme-switcher button { flex: 1; padding: .7rem .5rem; border-radius: 14px; border: 1px solid var(--border); background: transparent; color: var(--text); font-size: .9rem; cursor: pointer; }
.theme-switcher button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
