/* Dark (default) and light themes, switched via :root[data-theme] */
:root {
  color-scheme: dark;
  --bg: #0f0f10;
  --fg: #f2f2f4;
  --muted: #9a9aa3;
  --card: #1b1b1f;
  --border: #2a2a30;
  --accent: #3182f6;
  --accent-fg: #ffffff;
  --hl: #16243a;
  --ok-bg: #173d2a; --ok-fg: #7ee2a8;
  --wait-bg: #1e3a5f; --wait-fg: #cfe3ff;
  --end-bg: #2c2c33; --end-fg: #c4c4cc;
  --err: #ff7b7b;
  --radius: 16px;
  --ev-sub-bg: #52A3DE; --ev-sub-fg: #202124;
  --ev-refund-bg: #E4C966; --ev-refund-fg: #202124;
  --ev-wd-bg: #E45E7E; --ev-wd-fg: #202124;
  --ev-list-bg: #5CBB89; --ev-list-fg: #202124;
  --sun: #e5736f;
  --sat: #5b9bff;
  --up: #ff5a5f; --down: #4c9aff;
  --btn-bg: #2a2a30; --btn-hover: #34343b;
  --line: rgba(255,255,255,.12); --line-soft: rgba(255,255,255,.06);
  --row-alt: rgba(255,255,255,.025); --row-hover: rgba(255,255,255,.06); --ring: rgba(255,255,255,.08);
  --act-bg: #1f7a4d; --act-fg: #fff; --act-ring: #7ee2a8;
  --chip-bg: #2d2d34; --chip-bd: #3a3a44;
  --amber-bg: rgba(245,165,36,.16); --amber-bd: #f5a524; --amber-fg: #ffc46b;
  --pop-bg: #1b1b20; --pop-bd: #34343c; --pop-line: #2c2c34;
  --shadow-lg: 0 10px 40px rgba(0,0,0,.5); --shadow-md: 0 8px 24px rgba(0,0,0,.5);
  --m-card: #1c1c21; --other-bg: #151518; --card2: #222227; --card3: #1b1b1f; --tip-bg: #2c2c33;
  --switch-off: #3a3a42; --tab-bg: rgba(21,21,24,0.96);
  --toast-bg: #2a2a2f; --toast-fg: #fff;
  --cancel-bg: #3a3a42; --cancel-fg: #d0d0d6;
  --chg-bg: #4a3210; --chg-fg: #ffc46b;
  --mis-bg: #4a1c1c; --mis-fg: #ff9b9b;
  --unc-bg: #26343d; --unc-fg: #a9c4d4;
  --ga-bg: #173d2a; --ga-fg: #7ee2a8; --ga-bd: #2f6b4a;
  --gb-bg: #2e2350; --gb-fg: #c7b4ff; --gb-bd: #4f3d8a;
  --gc-bg: #4a1c1c; --gc-fg: #ff9b9b; --gc-bd: #7a3030;
  --evp-sub: #365D7B; --evp-refund: #7C7041; --evp-list: #3B6952; --evp-wd: #7C3C4D;
}

/* Light theme (user-selectable); higher specificity than :root so it wins regardless of order */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8; --fg: #1b1c1f; --muted: #6b6f78; --card: #ffffff; --border: #e2e4e9;
  --hl: #e6f0ff;
  --ok-bg: #dff5e8; --ok-fg: #1a7a48;
  --wait-bg: #dbeafe; --wait-fg: #1d4f91;
  --end-bg: #e9eaee; --end-fg: #5b5f68;
  --err: #d93025;
  --sun: #d64541; --sat: #2f6fe0;
  --up: #e5383b; --down: #2f6fe0;
  --btn-bg: #e9ebef; --btn-hover: #dcdfe5;
  --line: rgba(0,0,0,.09); --line-soft: rgba(0,0,0,.06);
  --row-alt: rgba(0,0,0,.025); --row-hover: rgba(0,0,0,.05); --ring: rgba(0,0,0,.1);
  --act-ring: #bfe9d2;
  --chip-bg: #eef0f4; --chip-bd: #d3d6dd;
  --amber-bg: rgba(245,165,36,.18); --amber-bd: #e09a12; --amber-fg: #8a5a00;
  --pop-bg: #ffffff; --pop-bd: #dfe1e6; --pop-line: #ebecf0;
  --shadow-lg: 0 10px 40px rgba(0,0,0,.18); --shadow-md: 0 8px 24px rgba(0,0,0,.15);
  --m-card: #ffffff; --other-bg: #eceef2; --card2: #eef0f4; --card3: #ffffff; --tip-bg: #e3e6ec;
  --switch-off: #c9ccd3; --tab-bg: rgba(255,255,255,0.94);
  --toast-bg: #26282d;
  --cancel-bg: #e4e5e9; --cancel-fg: #5b5f68;
  --chg-bg: #fdebd0; --chg-fg: #8a5a00;
  --mis-bg: #fde2e2; --mis-fg: #b42318;
  --unc-bg: #e3edf3; --unc-fg: #3e6378;
  --ga-bg: #dff5e8; --ga-fg: #1a7a48; --ga-bd: #9fd6b7;
  --gb-bg: #ebe5ff; --gb-fg: #5b3fc4; --gb-bd: #c4b5f5;
  --gc-bg: #fde2e2; --gc-fg: #b42318; --gc-bd: #f1a9a9;
  --evp-sub: #a9cde9; --evp-refund: #eedfa6; --evp-list: #aed8c2; --evp-wd: #efa9b9;
}

/* Theme toggle icon: sun in dark mode, moon in light mode */
#btn-theme .i-moon { display: none; }
:root[data-theme="light"] #btn-theme .i-sun { display: none; }
:root[data-theme="light"] #btn-theme .i-moon { display: inline; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", -apple-system, "Segoe UI", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1000px; margin: 0 auto; padding: 32px 16px calc(88px + env(safe-area-inset-bottom)); }

.header { display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 8px; }
h1 { margin: 0; font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; min-width: 0; }
h1 img { width: 32px; height: 32px; border-radius: 7px; flex: none; }

.actions { display: flex; flex-wrap: nowrap; gap: 6px; flex: none; }
.icon-btn { width: 36px; height: 36px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[hidden] { display: none; }
.icon-btn.spin svg { animation: icon-spin 0.8s linear infinite; }
@keyframes icon-spin { to { transform: rotate(360deg); } }
@media (max-width: 480px) { h1 { font-size: 1.25rem; } h1 img { width: 28px; height: 28px; } }

button {
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border: none;
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--fg);
  cursor: pointer;
  transition: background 0.15s, filter 0.15s;
}
@media (hover: hover) { button:hover:not(:disabled):not(.ev) { background: var(--btn-hover); } }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#btn-settings { background: var(--accent); color: var(--accent-fg); }
#btn-settings:hover:not(:disabled) { background: #4a93f8; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.status { min-height: 1.5em; margin: 16px 0; font-size: 0.92rem; color: var(--muted); }
.status.error { color: var(--err); }

.table-wrap { background: var(--card); border-radius: var(--radius); overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
th, td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; padding: 6px 10px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--row-hover); }
tbody tr.highlight { background: var(--hl); }
td:first-child { font-weight: 700; white-space: normal; overflow-wrap: anywhere; }
@media (min-width: 641px) { td:first-child { width: 340px; max-width: 340px; } }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.badge.active { background: var(--act-bg); color: var(--act-fg); box-shadow: 0 0 0 1px var(--act-ring); }
.badge.upcoming { background: var(--wait-bg); color: var(--wait-fg); }
.badge.listsoon { background: var(--ev-list-bg); color: var(--ev-list-fg); white-space: nowrap; }
.badge.blink { animation: badge-blink 1.1s ease-in-out infinite; }
@keyframes badge-blink { 50% { opacity: 0.25; } }
#test-result.blink { animation: badge-blink 0.5s ease-in-out 3; }
@media (prefers-reduced-motion: reduce) { .badge.blink { animation: none; } }
.bk-txt { color: var(--fg); }
.bk-t { white-space: nowrap; }
.metrics-m .bk-txt { font-size: 12px; }
.badge.closed { background: var(--end-bg); color: var(--end-fg); }

.empty { margin: 0; padding: 40px 16px; text-align: center; color: var(--muted); }

/* Broker chips: wrap instead of overflowing the column */
.bk-list { display: flex; flex-wrap: wrap; gap: 6px; }
td .bk-list { min-width: 220px; max-width: 420px; }
.bk { display: inline-flex; align-items: center; gap: 6px; line-height: 0; }
.bk svg, .bk-img { display: block; width: 24px; height: 24px; flex: none; border-radius: 22%; }
.bk-img { box-shadow: 0 0 0 1px var(--ring); object-fit: cover; }
.bk-named { gap: 6px; }
.bk-named .bk-name { font-size: 12px; font-weight: 600; line-height: 1.2; color: var(--fg); white-space: nowrap; }
.cal-detail .bk-list { gap: 6px 12px; }
.d-short { display: none; }
.metrics, .metrics-m { font-size: 12px; font-weight: 400; color: var(--muted); line-height: 1.4; margin-top: 2px; white-space: normal; word-break: keep-all; overflow-wrap: anywhere; }
.metrics .mi, .metrics-m .mi { display: inline-block; white-space: nowrap; }
.lv-chip { font: inherit; font-size: 11px; font-weight: 600; color: var(--fg); padding: 1px 8px; border: 1px solid var(--chip-bd); border-radius: 999px; background: var(--chip-bg); cursor: pointer; white-space: nowrap; }
.lv-chip:hover { background: var(--chip-bd); }
.st-wrap { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; white-space: nowrap; }
.lv-btn-m { display: none; }
.lv-chip.lv-btn { box-sizing: border-box; font-size: 0.78rem; font-weight: 700; line-height: normal; padding: 2px 10px; border: 1px solid var(--amber-bd); border-radius: 999px; background: var(--amber-bg); color: var(--amber-fg); }
.lv-chip.lv-btn:hover, .lv-chip.lv-btn:focus-visible { background: #f5a524; color: #1a1a1f; }
.lv-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lv-card { position: relative; width: 100%; max-width: 420px; background: var(--pop-bg); color: var(--fg); border: 1px solid var(--pop-bd); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-lg); }
.lv-close { position: absolute; top: 8px; right: 10px; border: none; background: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.lv-name { font-size: 1.1rem; font-weight: 700; padding-right: 28px; }
.lv-subtitle { margin-top: 4px; color: var(--muted); font-size: 0.85rem; }
.lv-rows { margin: 14px 0; }
.lv-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--pop-line); font-size: 0.92rem; }
.lv-row span { color: var(--muted); }
.lv-link { display: inline-block; font-weight: 600; }
.cal-listing { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.9rem; }
.cl-title { color: var(--muted); font-size: 0.8rem; margin-bottom: 4px; }
.cl-sub { margin-bottom: 4px; }
.cl-meta { margin-bottom: 6px; }
td.m-cell { display: none; }
.ft-lbl, .ft-r { display: none; }
.gchip { display: none; }
@media (max-width: 640px) {
  .container { padding: 20px 12px 40px; }
  h1 { font-size: 1.25rem; }
  .icon-btn { width: 32px; height: 32px; } .icon-btn svg { width: 18px; height: 18px; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  /* Compact card: line 1 name | status, line 2 inline-label meta, line 3 broker chips */
  .table-wrap { background: transparent; overflow-x: visible; }
  tbody { display: flex; flex-direction: column; gap: 10px; }
  tr, tbody tr:nth-child(even), tbody tr:hover { background: var(--m-card); }
  tbody tr.highlight { background: var(--hl); }
  tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
  td { display: block; padding: 0; border: none; white-space: normal; text-align: left; min-width: 0; }
  td::before { content: attr(data-label); display: inline; margin-right: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }
  td:nth-child(1)::before, td:nth-child(5)::before, td:nth-child(6)::before { display: none; }
  /* Row 1 (name | button+badge) is independent of row 2 widths: flex rows split by a full-width ::before */
  tr::before { content: ""; order: 3; flex: 0 0 100%; height: 0; margin-top: -4px; }
  td:nth-child(1) { order: 1; flex: 1 1 0; min-width: 0; }
  td:nth-child(1) .nm { display: inline-block; max-width: calc(100% - 44px); vertical-align: middle; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  td:nth-child(1) .grade { display: inline-flex; margin-left: 4px; }
  td:nth-child(6) { order: 2; flex: none; text-align: right; }
  /* 상장분석 button: moved from the status cell to the broker-chip line */
  .lv-btn-s { display: none; }
  td:nth-child(5) { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line-soft); padding-top: 6px; margin-top: 4px; }
  .ft-l { display: none; }
  .ft-r { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
  .ft-r:empty { display: none; }
  .grade.gchip { display: none; }
  td:nth-child(5) .lv-btn-m { display: inline-block; flex: none; }
  .lv-chip.lv-btn { font-size: 0.72rem; padding: 2px 8px; }
  /* 상장분석 button sits left of the status badge; broker line (only held the button) hidden */
  td:nth-child(5) { display: none !important; } .lv-btn-s { display: inline-block; } .st-wrap { flex-direction: row; align-items: center; gap: 6px; }
  td:nth-child(2), td:nth-child(3), td:nth-child(4) { flex: none; font-size: 0.82rem; white-space: nowrap; }
  td:nth-child(2) { order: 4; }
  td:nth-child(3) { order: 5; }
  td:nth-child(4) { order: 6; }
  td.m-cell { display: block; order: 7; flex: 0 0 100%; padding: 0; margin: 0; align-self: start; line-height: 1.4; }
  td.m-cell::before { display: none; }
  td.m-cell:empty { display: none; }
  .metrics-m { margin-top: 2px; }
  .metrics { display: none; }
  td.no-bk { display: none; }
  .d-full { display: none; }
  .d-short { display: inline; }
  .bk svg, .bk-img { width: 22px; height: 22px; }
  td .bk-list { min-width: 0; max-width: none; justify-content: flex-start; gap: 4px; }
  /* Phone card rules above target the IPO list; keep the prefs matrix a real table */
  .pm-table { display: table; width: 100%; } .pm-table thead { display: table-header-group; } .pm-table tbody { display: table-row-group; } .pm-table tr, .pm-table tbody tr:nth-child(even), .pm-table tbody tr:hover { display: table-row; padding: 0; border: 0; border-radius: 0; background: none; } .pm-table th, .pm-table td { display: table-cell; grid-column: auto; grid-row: auto; padding: 6px 4px; border: 0; margin: 0; vertical-align: middle; } .pm-table td::before { content: none; display: none; }
}

/* Cancelled / changed / mismatch / unconfirmed markers */
tr.withdrawn { opacity: 0.5; }
.badge.cancel { background: var(--cancel-bg); color: var(--cancel-fg); }
.badge.changed { background: var(--chg-bg); color: var(--chg-fg); }
.badge.mismatch { background: var(--mis-bg); color: var(--mis-fg); }
.badge.unconfirmed { background: var(--unc-bg); color: var(--unc-fg); }

/* Stacked sections: calendar on top, list below */
.cal-wrap { margin-bottom: 28px; }
.section-title { margin: 0 0 12px; font-size: 1.1rem; font-weight: 700; color: var(--fg); }
[hidden] { display: none !important; }

/* Calendar */
.cal-wrap { background: var(--card); border-radius: var(--radius); padding: 20px 16px; }
.cal-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-nav h2 { margin: 0 auto 0 4px; font-size: 1.2rem; font-weight: 800; order: -1; }
.cal-nav button { padding: 4px 14px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 0 14px; margin-bottom: 12px; }
/* Type filter checkboxes: >=32px tall tap target, plain text label */
.cal-legend .cal-chk { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; color: inherit; font-size: 0.9rem; }
.cal-legend .cal-toggle { -webkit-appearance: none; appearance: none; flex: none; width: 16px; height: 16px; margin: 0; cursor: pointer; border: 1.5px solid var(--muted); border-radius: 3px; background: transparent no-repeat center / 12px 12px; }
.cal-legend .cal-toggle:checked { background-color: var(--tc); border-color: var(--tc); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E"); }
.cal-legend .cal-toggle[data-type="sub"] { --tc: var(--ev-sub-bg); }
.cal-legend .cal-toggle[data-type="refund"] { --tc: var(--ev-refund-bg); }
.cal-legend .cal-toggle[data-type="list"] { --tc: var(--ev-list-bg); }
.cal-legend .cal-toggle[data-type="withdrawn"] { --tc: var(--ev-wd-bg); }
.cal-legend .cal-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-legend .cal-mine-toggle { -webkit-appearance: none; appearance: none; flex: none; width: 16px; height: 16px; margin: 0; cursor: pointer; border: 1.5px solid var(--muted); border-radius: 3px; background: transparent no-repeat center / 12px 12px; }
.cal-legend .cal-mine-toggle:checked { background-color: var(--accent); border-color: var(--accent); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E"); }
.cal-legend .cal-mine-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-hint { margin: 4px 0 8px; font-size: 0.82rem; color: var(--muted); }
.ev-mine { font-weight: 800; margin-right: 2px; }
/* "청약함" toggle chip (list rows + calendar detail) */
.mine-chk { display: inline-flex; align-items: center; gap: 5px; padding: 2px 0; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.78rem; font-weight: 700; line-height: 1.5; white-space: nowrap; cursor: pointer; }
.mine-chk .mine-box { flex: none; width: 16px; height: 16px; border: 1.5px solid var(--muted); border-radius: 3px; background: transparent no-repeat center / 12px 12px; }
.mine-chk[aria-checked="true"] { color: var(--fg); }
.mine-chk[aria-checked="true"] .mine-box { background-color: var(--accent); border-color: var(--accent); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E"); }
.mine-chk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-detail-mine { margin: 6px 0; }
td.mine-cell { display: none; }
.st-wrap .mine-d { margin-top: 2px; }
tbody tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
@media (max-width: 640px) {
  .mine-d { display: none; }
  td.mine-cell { display: block; order: 6; flex: none; margin-left: auto; }
  td.mine-cell::before { display: none; }
  td.mine-cell:empty { display: none; }
  tbody tr.mine { box-shadow: inset 3px 0 0 var(--accent); }
  tbody tr.mine td:first-child { box-shadow: none; }
}

.cal-grid { display: grid; grid-template-columns: minmax(0, .4fr) repeat(5, minmax(0, 1fr)) minmax(0, .4fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.cal-head { border-bottom: none; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.cal-head div { background: var(--card); text-align: center; font-size: 0.8rem; font-weight: 700; color: var(--muted); padding: 6px 0; }
.cal-head div:first-child { color: var(--sun); }
.cal-head div:last-child { color: var(--sat); }

.cal-cell { background: var(--card); min-height: 92px; padding: 3px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-cell.other { background: var(--other-bg); opacity: 0.5; }
.cal-cell.today { background: var(--hl); box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.cal-cell.sun .cal-day, .cal-cell.sat .cal-day { font-size: 0.68rem; }
.cal-head div:first-child, .cal-head div:last-child { font-size: 0.7rem; }
.cal-cell.sun, .cal-cell.sat { overflow: hidden; }
.cal-cell.sun .cal-day { color: var(--sun); }
.cal-cell.sat .cal-day { color: var(--sat); }
.cal-cell.today .cal-day { color: var(--accent); font-weight: 800; }

.ev {
  display: flex; align-items: center; gap: 3px; width: 100%; padding: 1px 4px; border: none; border-radius: 4px;
  font-size: 0.72rem; font-weight: 500; line-height: 1.4; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden;
}
/* Name/price text truncates; grade icon badge stays fixed */
.ev-pre { flex: none; margin-right: 2px; }
.ev-grade { flex: none; font-weight: 800; margin-right: 3px; }
.ev-txt { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.gicon {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; height: 1.5em; padding: 0 3px; border-radius: 6px;
  font-size: 0.56rem; font-weight: 800; line-height: 1;
}
.gsign { font-size: 0.85em; line-height: 1; vertical-align: baseline; }
.gicon.ga { background: var(--ga-bg); color: var(--ga-fg); border: 1px solid var(--ga-bd); }
.gicon.gb { background: var(--gb-bg); color: var(--gb-fg); border: 1px solid var(--gb-bd); }
.gicon.gc { background: var(--gc-bg); color: var(--gc-fg); border: 1px solid var(--gc-bd); }
@media (hover: hover) { .ev:hover:not(:disabled) { filter: brightness(1.15); } }
/* Multi-day subscription bars: segments join across cells (cell padding + 1px grid gap) */
.cal-cell { --cp: 3px; }
.ev-spacer { visibility: hidden; pointer-events: none; }
.ev-bar { position: relative; z-index: 1; border-radius: 0; }
.ev-bar.cap-l { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.ev-bar.cap-r { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.ev-bar.join-l { width: auto; margin-left: calc(-1 * (var(--cp) + 1px)); }
.ev-bar.join-r { width: auto; margin-right: calc(-1 * (var(--cp) + 1px)); }
/* First segment of a week-run: label spans the whole bar (N*seg + (N-2)*cp - 1px), above neighbors */
.cal-cell { --ep: 4px; }
.ev-bar.ev-first { overflow: visible; z-index: 2; }
.ev-lbl {
  position: absolute; left: var(--ep); top: 0; bottom: 0; display: flex; align-items: center; gap: inherit; overflow: hidden;
  /* Spans weekday cells (100% + w1a each) plus a narrow weekend cell (0.4x); lead = left offset of label inside bar */
  --w1a: calc(var(--cp) - 1px); --lead: var(--cp);
  width: calc((var(--nwd) + 0.4 * var(--nwe)) * (100% + var(--w1a)) + (var(--nwd) + var(--nwe) - 1) * 1px - var(--cp) - var(--lead) - 2 * var(--ep));
}
.ev-lbl.lbl-b { --w1a: -2px; --lead: -1px; }
.ev-sub { background: var(--ev-sub-bg); color: var(--ev-sub-fg); }
.ev-refund { background: var(--ev-refund-bg); color: var(--ev-refund-fg); }
.ev-list { background: var(--ev-list-bg); color: var(--ev-list-fg); }
.ev.withdrawn { background: var(--ev-wd-bg); color: var(--ev-wd-fg); text-decoration: line-through; }
.ev.past { opacity: 1; filter: none; } .ev-sub.past { background: var(--evp-sub); } .ev-refund.past { background: var(--evp-refund); } .ev-list.past { background: var(--evp-list); } .ev.withdrawn.past { background: var(--evp-wd); }
/* All text inside calendar events stays black */
.ev, .ev :not(.gicon):not(.gicon *) { color: #202124 !important; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.list-head .section-title { margin: 0; }
.past-toggle { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--end-bg); background: var(--end-bg); color: var(--end-fg); font-size: 0.85rem; cursor: pointer; }
.badge.listed { background: var(--end-bg); color: var(--end-fg); }

.cal-detail { margin-top: 16px; padding: 16px; background: var(--card2); border-radius: 12px; }
.cal-detail-head { display: flex; justify-content: space-between; align-items: center; font-size: 1.05rem; }
.cal-close { padding: 0 10px; font-size: 1.1rem; background: transparent; color: var(--muted); }
.cal-detail dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; font-size: 0.9rem; }
.cal-detail dt { color: var(--muted); }
.cal-detail dd { margin: 0; min-width: 0; }

@media (max-width: 640px) {
  .cal-wrap { padding: 12px 8px; }
  .cal-cell { min-height: 64px; padding: 2px; --cp: 2px; --ep: 2px; }
  .ev { font-size: 0.62rem; padding: 0 2px; border-radius: 3px; gap: 2px; }
  .gicon { font-size: 0.45rem; min-width: 1.4em; padding: 0 2px; border-radius: 4px; }
  .ev-price { display: none; }
  .ev-lbl {
    display: flex; align-items: center; min-width: 0; height: 100%; gap: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    width: calc(var(--nwd) * (100% + var(--w1a)) + var(--nwe) * 28px + (var(--nwd) + var(--nwe) - 1) * 1px - var(--cp) - var(--lead) - 2 * var(--ep));
  }
  .cal-grid { grid-template-columns: 28px repeat(5, minmax(0, 1fr)) 28px; }
  .cal-cell.sun .cal-day, .cal-cell.sat .cal-day { font-size: 0.6rem; }
  .cal-cell.sun, .cal-cell.sat { padding: 2px 1px; }
  .ev-lbl .ev-pre, .ev-lbl .gicon { flex: none; }
  .ev-lbl .ev-txt { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ev-bar { border-radius: 0; }
  .ev-bar.cap-l { border-top-left-radius: 3px; border-bottom-left-radius: 3px; }
  .ev-bar.cap-r { border-top-right-radius: 3px; border-bottom-right-radius: 3px; }
}

/* YouTube grade badge */
.grade { display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; width: 30px; height: 18px; padding: 0; border-radius: 6px; font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 0.74rem; line-height: 1; font-weight: 800; letter-spacing: 0; white-space: nowrap; text-decoration: none; vertical-align: middle; }
.grade.ga { background: var(--ev-list-bg); color: #202124; border: 1px solid var(--ev-list-bg); }
.grade.gb { background: var(--ev-sub-bg); color: #202124; border: 1px solid var(--ev-sub-bg); }
.grade.gc { background: var(--ev-wd-bg); color: #202124; border: 1px solid var(--ev-wd-bg); }

/* ---- Prefs panel, install banner, footer, privacy ---- */
.prefs-card { margin: 12px 0 0; padding: 12px 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.prefs-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.prefs-head h2 { margin: 0; font-size: 1.05rem; }
#prefs-close { width: 32px; height: 32px; font-size: 20px; line-height: 1; background: transparent; }
.prefs-test { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
#test-result { font-size: 0.85rem; }
#test-result.err { color: #D93025; }
.switch-row { display: flex; align-items: center; justify-content: space-between; font-weight: 600; cursor: pointer; }
#push-switch { appearance: none; -webkit-appearance: none; flex: none; width: 44px; height: 26px; margin: 0; border-radius: 999px; background: var(--switch-off); position: relative; cursor: pointer; transition: background 0.15s; }
#push-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
#push-switch:checked { background: var(--accent); }
#push-switch:checked::after { transform: translateX(18px); }
#push-switch:disabled { opacity: 0.5; cursor: not-allowed; }
#push-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.prefs-body { display: grid; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.prefs-body.off { opacity: 0.45; pointer-events: none; }
.prefs-body label { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.search { position: relative; margin: 10px 0 0; }
.search > svg { position: absolute; left: 11px; top: 19px; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
#search-input { display: block; width: 100%; height: 38px; padding: 0 36px 0 36px; font: inherit; font-size: 16px; background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; }
#search-input::placeholder { color: var(--muted); }
#search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search .search-clear { position: absolute; right: 3px; top: 3px; width: 32px; height: 32px; padding: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; }
.search .search-clear[hidden] { display: none; }
.search-list { position: absolute; z-index: 30; left: 0; right: 0; top: 42px; margin: 0; padding: 4px; list-style: none; max-height: 340px; overflow-y: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-md); }
.search-list[hidden] { display: none; }
.search-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.search-list li.active, .search-list li[data-i]:hover { background: var(--hl); }
.search-list .sg-nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-list .sg-meta { flex: none; font-size: 0.78rem; color: var(--muted); }
.search-list .sg-empty { color: var(--muted); cursor: default; justify-content: center; }
@keyframes sg-flash { 50% { background-color: rgba(49, 130, 246, 0.38); box-shadow: inset 0 0 0 2px var(--accent); } }
.pulse, .pulse > td { animation: sg-flash 0.7s ease-in-out 3; }
.pm-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.pm-table th, .pm-table td { padding: 5px 4px; text-align: center; vertical-align: middle; }
.pm-table thead th { font-size: 0.8rem; font-weight: 500; color: var(--muted, inherit); opacity: 0.8; }
.pm-table tbody th { text-align: left; white-space: nowrap; font-weight: 500; }
.pm-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.pm-times { text-align: left; }
.pm-chip { display: inline-flex; align-items: center; margin: 2px 4px 2px 0; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); }
.prefs-body .pm-chip select { margin: 0; border: 0; background: transparent; padding: 3px 0 3px 6px; font-size: 0.85rem; }
.pm-x, .pm-add { background: none; border: 0; color: var(--fg); cursor: pointer; padding: 2px 6px; font-size: 1rem; line-height: 1; }
.pm-add { border: 1px dashed var(--border); border-radius: 999px; margin: 2px 0; }
@media (max-width: 400px) {
  .pm-table { font-size: 0.82rem; }
  .pm-table th, .pm-table td { padding: 4px 2px; }
  .pm-dot { margin-right: 4px; }
}
.prefs-body select { margin-left: auto; background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.banner { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; padding: 10px 14px; background: var(--hl); border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }
.banner[hidden], .prefs-card[hidden] { display: none; }
.banner span { flex: 1; }
.banner #btn-install-close { margin-left: auto; }
.site-footer { margin: 32px 0 16px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); line-height: 1.6; }
.site-footer a, .privacy a { color: var(--accent); }
.privacy h2 { margin-top: 24px; font-size: 1.1rem; }
.privacy p, .privacy li { line-height: 1.7; color: var(--fg); }
.privacy .muted { color: var(--muted); }

/* ---- Bottom tab bar ---- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--tab-bg); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.tabbar-in { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 1000px; margin: 0 auto; }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: 6px 4px; border-radius: 0; background: transparent; color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.tab:hover:not(:disabled) { background: transparent; color: var(--fg); }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-pressed="true"] { color: var(--accent); }

/* ---- Performance tab ---- */
.perf-wrap { background: var(--card); border-radius: var(--radius); padding: 20px 16px; }
.perf-ctrl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { padding: 6px 12px; min-height: 36px; border-radius: 0; background: transparent; color: var(--muted); font-size: 0.85rem; }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.seg-btn:hover:not(:disabled):not([aria-pressed="true"]) { background: var(--btn-hover); }
.perf-spac { border: 1px solid var(--border); border-radius: 10px; }
.perf-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.pchip { padding: 3px 10px; border-radius: 999px; background: var(--card2); font-size: 0.8rem; color: var(--muted); }
.pchip b { color: var(--fg); font-weight: 700; }
.up { color: var(--up); } .down { color: var(--down); }
.perf-list { display: grid; gap: 8px; }
.perf-row { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.2fr) minmax(0, 1.6fr); align-items: center; gap: 4px 16px; padding: 10px 12px; background: var(--card2); border-radius: 12px; }
.perf-nm { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.perf-sub { font-size: 0.78rem; color: var(--muted); }
.perf-px { font-size: 0.88rem; }
.perf-ret { font-weight: 800; font-size: 1.05rem; }
.perf-row.has-chart { cursor: pointer; }
.perf-spark { position: relative; width: 100%; height: 44px; margin: 4px 0; overflow: hidden; }
.perf-spark svg { display: block; width: 100%; height: 100%; }
.ps-l { position: absolute; font-size: 0.68rem; line-height: 1.1; color: var(--muted); white-space: nowrap; pointer-events: none; background: var(--card2); padding: 0 3px; border-radius: 3px; }
.ps-dot { position: absolute; right: 0; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; pointer-events: none; }
.perf-big { grid-column: 1 / -1; min-width: 0; }
.perf-big:empty { display: none; }
.pb-plot { position: relative; height: 170px; margin: 8px 0 0 58px; touch-action: pan-y; cursor: crosshair; background: var(--card3); border-radius: 6px; }
.pb-plot svg { display: block; width: 100%; height: 100%; }
.pb-y { position: absolute; right: calc(100% + 6px); transform: translateY(-50%); font-size: 0.7rem; color: var(--muted); white-space: nowrap; pointer-events: none; }
.pb-y.pb-o { color: var(--fg); right: 6px; transform: translateY(-115%); }
.pb-x { display: flex; justify-content: space-between; margin: 4px 0 0 58px; font-size: 0.72rem; color: var(--muted); }
.pb-guide { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); pointer-events: none; }
.pb-dot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 1px solid var(--card3); pointer-events: none; }
.pb-tip { position: absolute; top: 4px; padding: 3px 8px; background: var(--tip-bg); border-radius: 6px; font-size: 0.78rem; white-space: nowrap; pointer-events: none; }
.pb-plot [hidden] { display: none; }
@media (max-width: 640px) {
  .perf-wrap { padding: 12px 8px; }
  .pb-plot, .pb-x { margin-left: 52px; }
  .pb-y { font-size: 0.64rem; }
  .perf-row { grid-template-columns: 1fr auto; }
  .perf-row > :nth-child(2) { grid-column: 1; grid-row: 2; }
  .perf-row > :nth-child(3) { grid-column: 1 / -1; grid-row: 3; }
}

/* Startup splash: calendar page flip (see app.js initSplash) */
#splash { position: fixed; inset: 0; z-index: 100; background: #0f0f10; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); animation: ss-failsafe .2s 4s forwards; }
#splash.ss-out { pointer-events: none; transition: opacity .5s ease-out; opacity: 0; }
.ss-icon { position: relative; width: 96px; height: 96px; perspective: 400px; will-change: transform; }
.ss-icon.ss-move { transition: transform .5s ease-out; }
.ss-icon svg { display: block; border-radius: 20px; }
.ss-name { margin-top: 14px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; white-space: nowrap; color: #fff; will-change: transform; }
.ss-name.ss-move { transition: transform .5s ease-out; }
.ss-name span { display: inline-block; opacity: 0; transition: color .5s ease-out; animation: ss-letter .2s calc(.75s + var(--i) * .06s) ease-out forwards; }
/* installed app: finished icon at exact center (matches native splash), typewriter name below */
.splash-app .ss-sheet { display: none; }
.ss-big { display: none; }
.splash-app .ss-big { display: block; position: fixed; left: 50%; top: 50%; width: min(272px, 75.5vw); height: min(272px, 75.5vw); transform: translate(-50%, calc(-50% + 4px)); clip-path: inset(6.7% round 28%); /* measured vs Android system splash: 218px squircle, 1.25x artwork, centered on full screen */ background: #000; opacity: 1; transition: opacity .35s ease-out; pointer-events: none; }
.splash-app .ss-big.ss-bigout { opacity: 0; }
.splash-app #splash { animation-delay: 5s; }
/* installed app: black screen 250ms, 56px launcher-style icon fades in, name types below, then plain cross-fade out */
.splash-app #splash { flex-direction: column; background: #000; padding-bottom: 14vh; }
.splash-app #splash.ss-out { transition: opacity .3s ease-out; opacity: 0; }
.splash-app .ss-icon { width: 56px; height: 56px; perspective: none; will-change: opacity; opacity: 0; transition: opacity .15s ease-out; }
.splash-app .ss-icon.ss-in { opacity: 1; }
.splash-app .ss-icon svg { width: 100%; height: 100%; border-radius: 22%; }
.splash-app .ss-name { margin: 8px 0 0; font-size: 16px; font-weight: 600; letter-spacing: 0; will-change: auto; }
.splash-app .ss-name span { animation: none; transform: none; transition: none; }
.splash-app .ss-name span.on { opacity: 1; }
.ss-caret { display: inline-block; width: 0; height: 1em; vertical-align: -.1em; position: relative; }
.ss-caret::after { content: ""; position: absolute; left: 1px; top: 0; width: 2px; height: 100%; background: #fff; animation: ss-blink .5s steps(1) infinite; }
@keyframes ss-blink { 50% { opacity: 0; } }
@keyframes ss-letter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.ss-sheet { position: absolute; left: 28.125%; top: 28.125%; width: 43.75%; height: 43.75%; background: #fff; transform-origin: 50% 0; box-shadow: 0 6px 14px rgba(0,0,0,.35); animation: ss-flip .7s 0s cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes ss-flip {
  0% { transform: rotateX(0); opacity: 1; box-shadow: 0 0 0 rgba(0,0,0,0); }
  60% { box-shadow: 0 10px 18px rgba(0,0,0,.4); }
  100% { transform: rotateX(-180deg); opacity: 0; box-shadow: 0 0 0 rgba(0,0,0,0); }
}
@keyframes ss-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }
@media (prefers-reduced-motion: reduce) { #splash { display: none; } }

/* ---- Onboarding overlay ---- */
.onb { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.6); overflow: hidden; }
.onb-card { position: relative; box-sizing: border-box; width: 100%; max-width: 420px; max-height: 100%; display: flex; flex-direction: column; gap: 12px; padding: 44px 16px 16px; background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-md); overflow: hidden; }
.onb-skip { position: absolute; top: 8px; right: 8px; font: inherit; font-size: 0.85rem; color: var(--muted); background: none; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.onb-viewport { overflow: hidden; touch-action: pan-y; min-height: 0; }
.onb-track { display: flex; transition: transform 0.3s ease; }
.onb-page { flex: 0 0 100%; min-width: 0; box-sizing: border-box; padding: 4px 8px; text-align: center; overflow-y: auto; max-height: 60vh; }
.onb-ico { display: flex; justify-content: center; gap: 12px; margin-bottom: 12px; color: var(--accent); }
.onb-ico svg { width: 44px; height: 44px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.onb-ico img { border-radius: 12px; }
.onb-page h2 { margin: 0 0 8px; font-size: 1.15rem; }
.onb-page p { margin: 0; font-size: 0.92rem; line-height: 1.55; color: var(--muted); word-break: keep-all; }
.onb-chips { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 14px; }
.onb-chip { padding: 3px 12px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.onb-static { cursor: default; pointer-events: none; }
.onb-dots { display: flex; justify-content: center; gap: 6px; }
.onb-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border); transition: background 0.2s, width 0.2s; }
.onb-dots i.on { width: 18px; border-radius: 4px; background: var(--accent); }
.onb-nav, .onb-last { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.onb-nav[hidden], .onb-last[hidden] { display: none; }
.onb-last { flex-direction: column; align-items: stretch; }
.onb-card button { font: inherit; }
.onb-prev, .onb-start { padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--fg); cursor: pointer; }
.onb-next, .onb-primary { padding: 9px 20px; border-radius: 10px; border: 0; background: var(--accent); color: var(--accent-fg); font-weight: 700; cursor: pointer; }
.onb-never { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-size: 0.8rem; color: var(--muted); cursor: pointer; }
.onb-never input { margin: 0; accent-color: var(--accent); }
.onb-card button:focus-visible, .onb-never input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .onb-track, .onb-dots i { transition: none; } }
