*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ══════════════════════════════════════
   DARK MODE
══════════════════════════════════════ */
:root, [data-theme="dark"] {
  --bg:        #000000;
  --bg2:       #0d0d0d;
  --bg3:       #141414;
  --bg4:       #1a1a1a;
  --border:    #222222;
  --border2:   #2e2e2e;

  --orange:    #FF6600;
  --green:     #00FF88;
  --red:       #FF1744;
  --red2:      #FF5252;
  --amber:     #FFB300;
  --cyan:      #00E5FF;
  --purple:    #CC44FF;
  --teal:      #00FFCC;
  --blue:      #4488FF;

  --text:      #F0F0F0;
  --text2:     #AAAAAA;
  --dim:       #555555;

  --topbar-bg:  #0d0d0d;
  --sidebar-bg: #0d0d0d;
  --card-bg:    #0d0d0d;
  --card-hover: #141414;

  --accent:    #FF6600;
  --accent2:   #FF8800;
}

/* ══════════════════════════════════════
   LIGHT MODE
══════════════════════════════════════ */
[data-theme="light"] {
  --bg:        #FFFFFF;
  --bg2:       #F5F5F5;
  --bg3:       #EBEBEB;
  --bg4:       #E0E0E0;
  --border:    #D0D0D0;
  --border2:   #BBBBBB;

  --orange:    #CC4400;
  --green:     #006633;
  --red:       #CC0022;
  --red2:      #AA0011;
  --amber:     #886600;
  --cyan:      #0066AA;
  --purple:    #6600AA;
  --teal:      #006655;
  --blue:      #0044CC;

  --text:      #0D0D0D;
  --text2:     #444444;
  --dim:       #888888;

  --topbar-bg:  #F5F5F5;
  --sidebar-bg: #F5F5F5;
  --card-bg:    #FFFFFF;
  --card-hover: #F5F5F5;

  --accent:    #CC4400;
  --accent2:   #AA3300;
}

:root {
  --font:       'IBM Plex Mono', 'Courier New', monospace;
  --sidebar:    230px;
  --topbar:     44px;
  --ticker:     26px;
  --catbar:     36px;
  --topoffset:  calc(var(--topbar) + var(--ticker) + var(--catbar));
  /* safe area for notch / Dynamic Island / foldable hinge */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

html {
  height: 100%;
  height: 100dvh;
}

body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
  /* prevent rubber-band scroll on iOS at body level */
  overscroll-behavior: none;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ══════════════════════════════════════
   SPLASH
══════════════════════════════════════ */
#aloha {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 500;
  transition: opacity 0.6s ease;
  padding-bottom: var(--safe-bottom);
}
#aloha.fade-out { opacity: 0; pointer-events: none; }
.aloha-text {
  font-size: clamp(40px, 14vw, 96px);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
  animation: pulse-in 0.5s ease;
}
.aloha-sub {
  font-size: clamp(9px, 2.5vw, 11px);
  letter-spacing: 0.3em;
  color: var(--dim);
  margin-top: 12px;
  font-weight: 600;
}
@keyframes pulse-in {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

/* ══════════════════════════════════════
   TOP BAR
══════════════════════════════════════ */
#topbar {
  position: fixed;
  top: 0; top: var(--safe-top);
  left: 0; right: 0;
  height: var(--topbar);
  background: var(--topbar-bg);
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  padding: 0 14px;
  padding-left: calc(14px + var(--safe-left));
  padding-right: calc(14px + var(--safe-right));
  gap: 10px;
  z-index: 100;
  user-select: none;
  transition: border-color 0.3s;
}
.tb-brand {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.12em;
  white-space: nowrap;
  transition: color 0.3s;
  flex-shrink: 0;
}
.tb-brand span { color: var(--text); }
.tb-divider { width: 1px; height: 22px; background: var(--border2); flex-shrink: 0; }
.tb-live {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--green); font-weight: 600; letter-spacing: 0.1em;
  flex-shrink: 0;
}
.tb-live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.25} }
.tb-updated {
  font-size: 10px; color: var(--dim); white-space: nowrap;
  letter-spacing: 0.06em; flex-shrink: 0;
}
.tb-stats {
  display: flex; gap: 8px; align-items: center;
  font-size: 11px; color: var(--text2); white-space: nowrap;
  overflow: hidden;
}
.tb-stats .s-val { font-weight: 700; }
.tb-clock { font-size: 11px; color: var(--text2); white-space: nowrap; }
.tb-date { color: var(--accent2); font-weight: 600; transition: color 0.3s; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#theme-toggle {
  background: none; border: 1px solid var(--border2);
  border-radius: 3px; cursor: pointer; padding: 4px 8px;
  font-family: var(--font); font-size: 11px; font-weight: 600;
  color: var(--text2); letter-spacing: 0.05em; transition: all 0.15s;
  /* min touch target */
  min-height: 32px; min-width: 44px;
  display: flex; align-items: center; justify-content: center;
}
#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
#hamburger {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 20px;
  padding: 0; flex-shrink: 0;
  /* touch target */
  min-width: 44px; min-height: 44px;
  display: none; align-items: center; justify-content: center;
}

/* ══════════════════════════════════════
   CATEGORY BAR
══════════════════════════════════════ */
#ticker-bar {
  position: fixed;
  top: calc(var(--safe-top) + var(--topbar));
  left: 0; right: 0;
  height: var(--ticker);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  z-index: 98;
}
#ticker-track {
  display: flex;
  align-items: center;
  height: 100%;
  white-space: nowrap;
  animation: ticker-run 35s linear infinite;
  will-change: transform;
}
@keyframes ticker-run {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
.tick-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 18px;
  font-size: 10px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.tick-sep { color: var(--border2); padding: 0 2px; flex-shrink: 0; font-size: 8px; }
.tick-sym { color: var(--dim); font-weight: 600; }
.tick-price { color: var(--text); font-weight: 700; }
.tick-chg { font-size: 9px; }
.tick-up { color: var(--green); }
.tick-dn { color: var(--red); }
@keyframes flash-up { 0%,100%{color:var(--text)} 50%{color:var(--green)} }
@keyframes flash-dn { 0%,100%{color:var(--text)} 50%{color:var(--red)} }
.flash-up { animation: flash-up 0.5s ease; }
.flash-dn { animation: flash-dn 0.5s ease; }

#catbar {
  position: fixed;
  top: calc(var(--safe-top) + var(--topbar) + var(--ticker));
  left: 0; right: 0;
  height: var(--catbar);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 99;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  touch-action: pan-x;
}
#catbar::-webkit-scrollbar { display: none; }
.cat-tab {
  flex-shrink: 0;
  padding: 0 14px;
  display: flex; align-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  color: var(--dim); cursor: pointer;
  border-bottom: 2px solid transparent;
  border-right: 1px solid var(--border);
  transition: all 0.15s;
  white-space: nowrap;
  /* touch target height */
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.cat-tab:hover { color: var(--text2); background: var(--bg3); }
.cat-tab:active { opacity: 0.8; }
.cat-tab.active { color: var(--bg) !important; border-bottom-color: transparent !important; }

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
#layout {
  display: flex;
  position: fixed;
  top: calc(var(--safe-top) + var(--topoffset));
  left: 0; right: 0;
  bottom: var(--safe-bottom);
}

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
#sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease, background 0.2s;
}
.sidebar-hdr {
  padding: 10px 12px 8px;
  font-size: 10px; font-weight: 700;
  color: var(--dim); letter-spacing: 0.15em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#date-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  padding: 6px 0;
  overscroll-behavior: contain;
}
.date-item {
  padding: 10px 12px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
  display: flex; flex-direction: column; justify-content: center;
}
.date-item:hover { background: var(--bg3); }
.date-item:active { background: var(--bg3); }
.date-item.active { border-left-color: var(--accent); background: var(--bg3); }
.di-date { font-size: 11px; font-weight: 600; color: var(--accent2); letter-spacing: 0.05em; transition: color 0.3s; }
.date-item.active .di-date { color: var(--accent); }
.di-meta { font-size: 9px; color: var(--dim); margin-top: 3px; }

/* ══════════════════════════════════════
   MAIN
══════════════════════════════════════ */
#main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 18px 20px 40px;
  overscroll-behavior: contain;
}

/* No data */
#no-data { padding: 60px 20px; text-align: center; color: var(--dim); font-size: 12px; line-height: 2.2; }
.no-data-label { font-size: 32px; color: var(--accent); font-weight: 700; margin-bottom: 14px; transition: color 0.3s; }

/* Brief header */
#brief-hdr { border-bottom: 1px solid var(--border2); padding-bottom: 12px; margin-bottom: 16px; }
.bh-date { font-size: 10px; font-weight: 700; letter-spacing: 0.15em; color: var(--accent); margin-bottom: 4px; transition: color 0.3s; }
.bh-headline { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.4; }
.bh-meta { font-size: 10px; color: var(--text2); margin-top: 6px; display: flex; gap: 14px; flex-wrap: wrap; }
.bh-meta .num { font-weight: 700; color: var(--accent); transition: color 0.3s; }

/* Signal — Key Takeaways */
#signal-box {
  background: var(--bg2); border: 1px solid var(--border2);
  border-left: 3px solid var(--accent);
  border-radius: 2px; padding: 12px 14px; margin-bottom: 20px;
  transition: border-left-color 0.3s;
}
.signal-hdr { font-size: 10px; font-weight: 700; letter-spacing: 0.15em; color: var(--accent); margin-bottom: 10px; transition: color 0.3s; }
.signal-item { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--border); }
.signal-item:last-child { border-bottom: none; padding-bottom: 0; }
.signal-num { font-size: 13px; color: var(--accent); flex-shrink: 0; font-weight: 700; transition: color 0.3s; min-width: 22px; }
.signal-text { font-size: 12px; color: var(--text); line-height: 1.5; }

/* Summary cards */
.stories-hdr {
  font-size: 10px; font-weight: 700; letter-spacing: 0.15em;
  color: var(--dim); margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.stories-hdr::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.qh-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 24px; }
.qh-item {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 2px; padding: 9px 12px;
  display: flex; align-items: flex-start; gap: 10px;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.qh-item:hover { background: var(--card-hover); border-color: var(--border2); }
.qh-bullet { color: var(--accent); flex-shrink: 0; font-size: 10px; margin-top: 3px; transition: color 0.3s; }
.qh-text { font-size: 11px; color: var(--text2); line-height: 1.65; }
.qh-text a { color: var(--blue); text-decoration: none; }
.qh-text a:hover { color: var(--cyan); text-decoration: underline; }

/* Sources */
.sources-section { margin-top: 20px; }
.ss-hdr {
  font-size: 10px; font-weight: 700; letter-spacing: 0.15em;
  color: var(--dim); margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.ss-hdr::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.src-list { display: flex; flex-direction: column; gap: 3px; }
.src-item { font-size: 10px; color: var(--dim); }
.src-item a { color: var(--blue); text-decoration: none; }
.src-item a:hover { color: var(--cyan); }

/* ══════════════════════════════════════
   TELEGRAM
══════════════════════════════════════ */
.tg-summary-bar {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 2px; padding: 8px 12px; margin-bottom: 16px;
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 10px; color: var(--text2);
}
.tg-summary-bar .num { font-weight: 700; color: var(--accent); transition: color 0.3s; }
.tg-group {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 2px; margin-bottom: 8px; overflow: hidden;
}
.tg-group-head {
  padding: 11px 12px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  transition: background 0.15s;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.tg-group-head:hover { background: var(--card-hover); }
.tg-group-head:active { background: var(--card-hover); }
.tg-group-name { font-size: 11px; font-weight: 700; color: var(--text); letter-spacing: 0.05em; flex: 1; }
.tg-msg-count { font-size: 10px; font-weight: 600; flex-shrink: 0; }
.tg-msg-count.active { color: var(--green); }
.tg-msg-count.quiet  { color: var(--amber); }
.tg-msg-count.silent { color: var(--dim); }
.tg-expand { font-size: 10px; color: var(--dim); transition: transform 0.2s; flex-shrink: 0; }
.tg-group.open .tg-expand { transform: rotate(180deg); }
.tg-group-body { display: none; border-top: 1px solid var(--border); padding: 10px 12px; }
.tg-group.open .tg-group-body { display: block; }
.tg-bullets { list-style: none; padding: 0; }
.tg-bullets li {
  font-size: 11px; color: var(--text2); line-height: 1.6;
  padding: 3px 0 3px 14px; position: relative;
}
.tg-bullets li::before { content: '◆'; position: absolute; left: 0; font-size: 7px; color: var(--accent); top: 6px; transition: color 0.3s; }
.tg-empty { font-size: 11px; color: var(--dim); font-style: italic; }
.tg-alerts { margin-top: 8px; }
.tg-alert { font-size: 11px; color: var(--amber); font-weight: 600; padding: 4px 0; }

/* ══════════════════════════════════════
   MOBILE DATE BAR (chips)
══════════════════════════════════════ */
#mobile-datebar {
  display: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 6px;
  padding: 8px 0 8px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  margin: -18px -20px 14px;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  touch-action: pan-x;
}
#mobile-datebar::-webkit-scrollbar { display: none; }
.mob-date-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 2px; cursor: pointer;
  font-size: 10px; font-weight: 600; letter-spacing: 0.05em;
  border: 1px solid var(--border2); color: var(--text2);
  background: var(--bg3); white-space: nowrap;
  transition: all 0.15s;
  min-height: 32px; display: inline-flex; align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.mob-date-chip.active { color: var(--bg); border-color: var(--accent); background: var(--accent); }

/* ══════════════════════════════════════
   SIDEBAR OVERLAY
══════════════════════════════════════ */
#sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); z-index: 90;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#empty-state { padding: 40px 20px; text-align: center; color: var(--dim); font-size: 12px; line-height: 2; }

/* ══════════════════════════════════════
   RESPONSIVE — TABLET / FOLDABLE OPEN
   600px–900px (e.g. Galaxy Z Fold unfolded, iPad mini)
══════════════════════════════════════ */
@media (min-width: 601px) and (max-width: 900px) {
  :root { --sidebar: 190px; }
  .tb-stats { display: none; }
  .tb-clock { font-size: 10px; }
  .cat-tab { padding: 0 10px; font-size: 9px; }
  .bh-headline { font-size: 14px; }
  #main { padding: 14px 16px 40px; }
}

/* ══════════════════════════════════════
   RESPONSIVE — PHONE (portrait 9:16 / 9:19.5)
   ≤ 600px
══════════════════════════════════════ */
@media (max-width: 600px) {
  :root {
    --topbar: 48px;
    --catbar: 40px;
    --topoffset: 88px;
  }

  html, body { font-size: 12px; overflow: hidden; }

  /* sidebar slides in over content */
  #sidebar {
    position: fixed;
    top: calc(var(--safe-top) + var(--topoffset));
    left: 0; bottom: var(--safe-bottom);
    z-index: 95;
    width: min(280px, 80vw);
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay.open { display: block; }

  /* hamburger visible */
  #hamburger { display: flex; }

  /* hide desktop stats and live indicator */
  .tb-stats { display: none; }
  .tb-divider { display: none; }
  .tb-live { display: none; }
  .tb-updated { display: none; }

  /* clock: time only on small screens */
  .tb-date { display: none; }
  .tb-clock { font-size: 11px; }

  /* mobile date bar shows */
  #mobile-datebar { display: flex; }

  /* catbar: smaller tabs, full width scroll */
  .cat-tab { padding: 0 10px; font-size: 9px; letter-spacing: 0.08em; }

  /* main content */
  #main { padding: 10px 14px calc(40px + var(--safe-bottom)); }
  .bh-headline { font-size: 13px; }
  .bh-date { letter-spacing: 0.08em; font-size: 9px; }
  .bh-meta { gap: 8px; font-size: 9px; }

  /* signal box tighter */
  #signal-box { padding: 10px 12px; }
  .signal-text { font-size: 11px; }
  .signal-num { font-size: 12px; }

  /* cards full width, bigger touch targets */
  .qh-item { padding: 10px 10px; }
  .qh-text { font-size: 11px; }

  /* telegram */
  .tg-group-head { padding: 12px 10px; }
  .tg-group-name { font-size: 10px; }
  .tg-group-body { padding: 8px 10px; }
  .tg-bullets li { font-size: 10px; }
}

/* ══════════════════════════════════════
   FOLDABLE — cover display (very narrow, ~280-360px)
══════════════════════════════════════ */
@media (max-width: 380px) {
  :root { --topbar: 44px; --catbar: 36px; --topoffset: 80px; }

  .tb-brand { font-size: 12px; letter-spacing: 0.06em; }
  #theme-toggle { font-size: 10px; padding: 3px 6px; min-width: 36px; }

  .cat-tab { padding: 0 8px; font-size: 8px; letter-spacing: 0.05em; }

  #main { padding: 8px 10px calc(36px + var(--safe-bottom)); }
  .bh-headline { font-size: 12px; }

  .qh-item { padding: 8px; gap: 8px; }
  .qh-text { font-size: 10px; }
}

/* ══════════════════════════════════════
   LANDSCAPE PHONE (rotated 9:16)
══════════════════════════════════════ */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  :root { --topbar: 36px; --catbar: 30px; --topoffset: 66px; }

  .aloha-text { font-size: clamp(32px, 8vw, 60px); }
  .tb-brand { font-size: 12px; }
  #theme-toggle { padding: 2px 6px; font-size: 10px; }
  .cat-tab { height: 30px; font-size: 9px; padding: 0 8px; }
  #main { padding: 8px 14px 24px; }
  .bh-headline { font-size: 12px; }

  /* In landscape, show a persistent narrow sidebar instead of overlay */
  #sidebar {
    position: relative;
    transform: none !important;
    width: 160px;
    box-shadow: none;
  }
  #sidebar-overlay { display: none !important; }
  #hamburger { display: none !important; }
  #mobile-datebar { display: none !important; }
}
