:root {
  color-scheme: dark;
  --bg: #0b0f15;
  --surface: #111722;
  --surface-2: #171f2c;
  --surface-3: #202a39;
  --border: #263244;
  --text: #f5f8fc;
  --muted: #8f9bae;
  --green: #36d399;
  --blue: #5aa7ff;
  --danger: #f87171;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; min-height: 100%; background: var(--bg); }
body { margin: 0; background: radial-gradient(circle at 75% -15%, #152638 0, transparent 34%), var(--bg); color: var(--text); min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; min-height: 100dvh; }

.main-content { min-width: 0; max-width: 1560px; width: 100%; margin: 0 auto; padding: 42px clamp(24px, 4vw, 64px) 64px; transition: opacity .15s; }
.main-content.is-loading { opacity: .65; }
.page-header { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 30px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(30px, 3.4vw, 46px); line-height: 1.05; letter-spacing: -1.6px; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.3px; }
.eyebrow { color: var(--green); text-transform: uppercase; letter-spacing: 1.7px; font-size: 10px; font-weight: 800; margin-bottom: 9px; }
.muted { color: var(--muted); }
.page-header .muted { margin-bottom: 0; font-size: 14px; }
.filters { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.live-control { display: grid; justify-items: end; gap: 5px; }
.live-control > span { max-width: 230px; color: var(--muted); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-control .button.danger { border-color: #f8717155; background: #f871711c; color: #ff9b9b; box-shadow: none; }
label { display: grid; gap: 7px; color: #b9c3d1; font-size: 12px; font-weight: 600; }
label > span, fieldset legend { color: var(--muted); text-transform: uppercase; letter-spacing: .7px; font-size: 9px; font-weight: 800; }
select, input { height: 42px; min-width: 124px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); padding: 0 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
select:focus, input:focus { border-color: var(--green); box-shadow: 0 0 0 3px #36d39918; }
.custom-range { display: flex; gap: 10px; align-items: end; }
.detail-page > .custom-range { justify-content: flex-end; margin: -18px 0 24px; }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.metric-grid.four { grid-template-columns: repeat(4, 1fr); }
.metric-card { min-height: 118px; border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, #151d29, #101620); padding: 22px; display: flex; align-items: center; gap: 16px; box-shadow: 0 16px 40px #00000022; }
.metric-card > div, .metric-card.compact { display: grid; gap: 4px; }
.metric-card span { color: #aab5c5; font-size: 12px; }
.metric-card strong { font-size: 27px; letter-spacing: -.8px; }
.metric-card small { color: #68768a; font-size: 11px; }
.metric-icon { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 22px !important; }
.metric-icon.green { color: var(--green); background: #36d39916; }
.metric-icon.blue { color: var(--blue); background: #5aa7ff16; }
.metric-card.compact { align-content: center; min-height: 100px; }
.metric-card.compact strong { font-size: 23px; }

.panel { border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, rgba(20, 27, 39, .96), rgba(14, 20, 29, .96)); box-shadow: 0 18px 50px #00000020; padding: 23px; min-width: 0; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 22px; }
.panel-heading .eyebrow { margin-bottom: 5px; }
.panel-heading .muted { font-size: 12px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(280px, .75fr); gap: 18px; margin-bottom: 18px; }

.game-list { display: grid; }
.game-row { display: grid; grid-template-columns: 30px 86px minmax(0, 1fr) 92px 22px; align-items: center; gap: 13px; border-top: 1px solid #263244bb; padding: 14px 4px; transition: .18s ease; }
.game-row:first-child { border-top: 0; padding-top: 5px; }
.game-row:hover { transform: translateX(4px); }
.game-row:hover .row-arrow { color: var(--green); }
.rank { color: #536075; font-size: 11px; font-weight: 800; }
.game-cover-thumb { width: 84px; height: 108px; display: grid; place-items: center; border-radius: 12px; background: #36d39916; color: var(--green); font-size: 18px; font-weight: 900; overflow: hidden; }
.game-cover-thumb img, .manual-mark img { width: 100%; height: 100%; object-fit: cover; }
.game-info { display: grid; gap: 10px; min-width: 0; }
.game-info > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.game-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-info span, .game-duration span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.progress { height: 5px; border-radius: 6px; background: #253041; overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--blue)); }
.game-duration { display: grid; text-align: right; gap: 3px; }
.game-duration strong { font-size: 14px; }
.row-arrow { color: #526074; transition: color .15s; }

.donut-wrap { display: grid; place-items: center; gap: 28px; }
.donut { width: min(190px, 72%); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; position: relative; }
.donut::after { content: ""; position: absolute; inset: 25%; border-radius: 50%; background: #111822; border: 1px solid var(--border); }
.donut span { position: relative; z-index: 1; font-weight: 800; font-size: 16px; }
.legend { display: grid; gap: 10px; width: 100%; }
.legend > div { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 9px; align-items: center; font-size: 11px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; }
.legend span { color: #a9b4c3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.month-panel { margin-bottom: 18px; }
.manual-games-panel { margin-bottom: 18px; }
.panel-actions { display: flex; align-items: center; gap: 9px; }
.manual-game-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.manual-game-card { display: grid; grid-template-columns: 38px minmax(0, 1fr) 20px; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 13px; background: #171f2c88; padding: 14px; transition: transform .15s, border-color .15s; }
.manual-game-card:hover { transform: translateY(-2px); border-color: #36d39966; }
.manual-game-card > div { display: grid; gap: 4px; min-width: 0; }
.manual-game-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.manual-game-card div span { color: var(--muted); font-size: 10px; }
.manual-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: #36d39918; color: var(--green); font-size: 11px; font-weight: 900; }
.manual-mark.has-image { height: 44px; overflow: hidden; }
.compact-empty { min-height: 90px; }
.bar-chart { height: 230px; display: grid; grid-template-columns: repeat(12, minmax(20px, 1fr)); align-items: end; gap: clamp(5px, 1vw, 13px); border-bottom: 1px solid var(--border); padding: 34px 6px 0; }
.bar-column { height: 100%; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 7px; position: relative; }
.bar-column i { display: block; width: min(34px, 70%); min-height: 1px; background: linear-gradient(180deg, var(--green), #147c5b); border-radius: 7px 7px 2px 2px; transition: filter .18s; }
.bar-column:hover i { filter: brightness(1.3); }
.bar-column small { position: absolute; top: calc(100% + 8px); color: var(--muted); font-size: 9px; }
.bar-value { font-size: 9px; color: #aab5c5; min-height: 12px; }
.compact-chart { height: 196px; }

.button { display: inline-flex; align-items: center; justify-content: center; height: 42px; border: 1px solid transparent; border-radius: 10px; padding: 0 15px; color: var(--text); background: var(--surface-3); cursor: pointer; font-weight: 700; font-size: 12px; transition: transform .15s, background .15s, opacity .15s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button.primary { background: var(--green); color: #061b13; box-shadow: 0 8px 26px #36d39922; }
.button.secondary { border-color: var(--border); background: var(--surface-2); color: #c7d0dc; }
.button.danger { border-color: #f8717144; color: #ff9b9b; background: #f8717112; }
.button.small { height: 34px; padding: 0 12px; }
.button.full { width: 100%; margin-top: 8px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.back-link { display: inline-block; color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.back-link:hover { color: var(--green); }
.hero-total { color: var(--green); font-weight: 700; margin: 10px 0 0; }
.game-hero { display: flex; align-items: center; gap: 22px; min-width: 0; }
.game-cover-large { flex: 0 0 auto; width: 112px; height: 150px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--border); border-radius: 15px; background: linear-gradient(145deg, #1b2837, #111722); color: var(--green); font-size: 28px; font-weight: 900; box-shadow: 0 18px 45px #0005; }
.game-cover-large img { width: 100%; height: 100%; object-fit: cover; }
.game-cover-large.has-image > span { display: none; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, .75fr); gap: 18px; margin-bottom: 18px; }
.insight-panel, .how-panel { padding-bottom: 8px; }
.insight-row { display: flex; align-items: center; gap: 13px; border-top: 1px solid var(--border); padding: 14px 0; }
.insight-row:first-child { border-top: 0; padding-top: 2px; }
.insight-icon { flex: 0 0 auto; display: grid; place-items: center; width: 29px; height: 29px; border-radius: 9px; background: #36d39915; color: var(--green); font-size: 10px; font-weight: 900; }
.insight-row > div { display: grid; gap: 2px; min-width: 0; }
.insight-row small { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .7px; }
.insight-row strong { font-size: 14px; }
.insight-row div span { color: #718097; font-size: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.session-list { display: grid; }
.session-row { display: grid; grid-template-columns: 70px minmax(0, 1fr) 105px 72px; align-items: center; gap: 16px; border-top: 1px solid var(--border); padding: 16px 2px; }
.session-row:first-child { border-top: 0; }
.session-date, .session-times, .session-length { display: grid; gap: 4px; }
.session-date strong { font-size: 15px; }
.session-date span, .session-times span, .session-length span { color: var(--muted); font-size: 10px; }
.session-times strong { font-size: 12px; }
.session-length { text-align: right; }
.active-pill { color: var(--green); font-style: normal; }

.calendar-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, .7fr); gap: 18px; }
.heatmap-panel { overflow: hidden; }
.heat-legend { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 9px; }
.heat-legend i { width: 10px; height: 10px; border-radius: 2px; background: #202a39; }
.heat-legend i:nth-of-type(2) { background: #164b3b; }
.heat-legend i:nth-of-type(3) { background: #1c7657; }
.heat-legend i:nth-of-type(4) { background: #27a977; }
.heat-legend i:nth-of-type(5) { background: var(--green); }
.heatmap { display: flex; gap: 9px; overflow-x: auto; padding: 2px 0 12px; }
.heat-weekdays { flex: 0 0 23px; display: grid; grid-template-rows: repeat(4, 1fr); color: #627087; font-size: 8px; height: 106px; align-items: center; }
.heat-cells { height: 106px; display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; }
.heat { width: 12px; height: 12px; border-radius: 3px; background: #202a39; }
.heat.empty { visibility: hidden; }
.heat.level-1 { background: #164b3b; }
.heat.level-2 { background: #1c7657; }
.heat.level-3 { background: #27a977; }
.heat.level-4 { background: var(--green); box-shadow: 0 0 8px #36d39936; }

.drawer { position: fixed; inset: 0 0 0 auto; width: min(440px, 100vw); z-index: 40; background: #111722; border-left: 1px solid var(--border); box-shadow: -26px 0 80px #00000088; padding: 30px; overflow-y: auto; transform: translateX(100%); transition: transform .18s ease; }
.drawer.open { transform: translateX(0); }
.drawer-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 28px; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 21px; }
#session-form { display: grid; gap: 17px; }
#session-form label { font-size: 11px; }
#session-form input:not([type=radio]) { width: 100%; }
fieldset { border: 1px solid var(--border); border-radius: 12px; margin: 0; padding: 13px; display: grid; gap: 10px; }
.radio-row { display: flex !important; align-items: center; gap: 9px; color: #cad2dd; }
.radio-row input { width: 15px !important; height: 15px; min-width: 0; accent-color: var(--green); }
.duration-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.duration-preview { display: flex; justify-content: space-between; padding: 14px; border-radius: 10px; background: #36d3990d; border: 1px solid #36d3992b; color: var(--muted); font-size: 11px; }
.duration-preview strong { color: var(--green); }
.form-error { min-height: 16px; color: #ff8e8e; font-size: 11px; margin: 0; }
.form-success { min-height: 16px; color: var(--green); font-size: 11px; line-height: 1.55; margin: 0; }

.modal-backdrop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: #05080db8; backdrop-filter: blur(12px); padding: 20px; }
.auth-card { position: relative; width: min(410px, 100%); border: 1px solid var(--border); border-radius: 22px; background: linear-gradient(150deg, #192231, #101620); box-shadow: 0 30px 100px #000; padding: 34px; display: grid; gap: 15px; }
.options-card { position: relative; width: min(720px, 100%); max-height: min(860px, 92vh); overflow-y: auto; border: 1px solid var(--border); border-radius: 22px; background: linear-gradient(150deg, #192231, #101620); box-shadow: 0 30px 100px #000; padding: 30px; display: grid; gap: 17px; }
.options-card > div:first-of-type .muted { margin: 8px 0 0; font-size: 12px; }
.cover-editor-preview { width: 126px; height: 168px; justify-self: center; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: #0e141d; color: var(--green); font-size: 28px; font-weight: 900; }
.cover-editor-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-editor-preview.has-image > span { display: none; }
.option-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.options-divider { display: flex; align-items: center; gap: 12px; color: #68768a; font-size: 9px; text-transform: uppercase; letter-spacing: 1px; }
.options-divider::before, .options-divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }
.game-id-editor { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; }
.game-id-editor > div { display: grid; gap: 7px; }
.game-id-editor input { width: 100%; }
.game-id-editor .muted, .source-note { margin: 0; font-size: 10px; line-height: 1.5; }
.source-note { color: #8da0b8; overflow-wrap: anywhere; }
.igdb-search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; }
.igdb-search-row input { width: 100%; }
.igdb-results { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.igdb-result { min-width: 0; border: 1px solid var(--border); border-radius: 10px; padding: 7px; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; gap: 7px; text-align: left; transition: border-color .15s, transform .15s; }
.igdb-result:hover, .igdb-result.selected { border-color: var(--green); transform: translateY(-2px); }
.igdb-result img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 7px; background: #0b0f15; }
.igdb-result span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.auth-card h2 { font-size: 25px; }
.auth-card p { margin-bottom: 0; line-height: 1.6; }
.auth-mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: #36d39918; color: var(--green); }
.modal-close { position: absolute; right: 18px; top: 18px; }
.attempt-note { text-align: center; color: #66758a; font-size: 10px; }
.import-card { width: min(520px, 100%); }
.folder-picker { display: grid; gap: 8px; }
.folder-picker input { width: 100%; padding: 12px; height: auto; }
.folder-selection { color: #8da0b8; font-size: 11px; margin: -4px 0 0; }

.empty-state, .loading { min-height: 160px; display: grid; place-content: center; text-align: center; gap: 6px; color: var(--muted); font-size: 12px; }
.empty-state strong { color: var(--text); font-size: 14px; }

@media (max-width: 1050px) {
  .metric-grid.four { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .detail-grid, .calendar-grid { grid-template-columns: 1fr; }
  .breakdown-panel .donut-wrap { grid-template-columns: minmax(140px, 220px) 1fr; }
}

@media (max-width: 720px) {
  .main-content { padding: max(26px, env(safe-area-inset-top)) max(17px, env(safe-area-inset-right)) 40px max(17px, env(safe-area-inset-left)); }
  .page-header { align-items: stretch; flex-direction: column; }
  .filters { width: 100%; }
  .filters label { flex: 1; }
  .filters select { width: 100%; }
  .metric-grid, .metric-grid.four { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 94px; padding: 16px; }
  .metric-card:first-child { grid-column: 1 / -1; }
  .metric-card strong { font-size: 21px; }
  .metric-icon { width: 38px; height: 38px; }
  .panel { padding: 18px; border-radius: 15px; }
  .game-row { grid-template-columns: 18px 74px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; align-items: center; column-gap: 10px; row-gap: 8px; padding-block: 14px; }
  .game-row .rank { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
  .game-cover-thumb { width: 72px; height: 94px; }
  .game-row .game-cover-thumb { grid-column: 2; grid-row: 1 / span 2; }
  .game-row .game-info { grid-column: 3; grid-row: 1; align-self: end; gap: 8px; }
  .game-row .game-info > div:first-child { display: grid; justify-content: stretch; gap: 4px; }
  .game-row .game-info strong { display: -webkit-box; overflow: hidden; white-space: normal; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.25; font-size: 14px; }
  .game-row .game-info span { white-space: normal; line-height: 1.3; }
  .game-row .game-duration { grid-column: 3; grid-row: 2; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; text-align: left; }
  .game-row .game-duration strong { font-size: 13px; }
  .row-arrow { display: none; }
  .breakdown-panel .donut-wrap { grid-template-columns: 1fr; }
  .bar-chart { height: 190px; gap: 3px; overflow: visible; }
  .bar-column { min-width: 20px; }
  .bar-value { display: none; }
  .session-row { grid-template-columns: 62px minmax(0, 1fr) 64px; gap: 9px; }
  .session-length { display: none; }
  .button.small { padding: 0 8px; }
  .custom-range { width: 100%; }
  .custom-range label { flex: 1; }
  .custom-range input { width: 100%; min-width: 0; }
  .game-hero { align-items: flex-start; }
  .game-cover-large { width: 82px; height: 110px; border-radius: 12px; }
  .options-card { padding: 24px 18px; }
  .igdb-results { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-actions { width: 100%; }
  .panel-actions .button { flex: 1; }
  .game-id-editor { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .metric-grid, .metric-grid.four { grid-template-columns: 1fr; }
  .metric-card:first-child { grid-column: auto; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters .button { grid-column: 1 / -1; }
}
