:root {
  --c1: var(--th-bg);
  --c2: var(--th-panel);
  --c3: var(--th-border-hi);

  --bg:         var(--th-bg);
  --surface:    var(--th-panel);
  --card:       var(--th-mid);
  --border:     var(--th-border);
  --border-hi:  var(--th-border-hi);

  --text-hi:    var(--th-text);
  --text-mid:   var(--th-text);
  --text-low:   var(--th-text-quiet);

  --accent:     var(--th-accent);
  --live-dot:   var(--th-ok);

  --font-head:  'Syne', sans-serif;
  --font-mono:  'DM Mono', monospace;
}

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

body {
  background: var(--bg);
  color: var(--text-hi);
  font-family: var(--font-mono);
  height: 100vh;
  overflow: hidden;
  background-image: repeating-linear-gradient(
    135deg,
    transparent,
    transparent 40px,
    rgba(233,238,227,0.035) 40px,
    rgba(233,238,227,0.035) 41px
  );
}

/* ── HEADER ──────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(233,238,227,0.06);
}

.header-left { display: flex; align-items: baseline; gap: 14px; }

.h-logo {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: var(--text-hi);
}

.h-sep {
  width: 1px; height: 14px;
  background: var(--border);
  align-self: center;
}

.h-sub {
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--text-low);
  text-transform: uppercase;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--th-text-faint);
  flex-shrink: 0;
  transition: background 0.3s;
}

.dot.online {
  background: var(--live-dot);
  animation: blink-dot 2s ease-in-out infinite;
}

@keyframes blink-dot {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

#status-txt {
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--text-low);
  text-transform: uppercase;
}

/* ── LOG AREA ─────────────────────────────────────────────── */
#log-box {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#log-box::-webkit-scrollbar { width: 3px; }
#log-box::-webkit-scrollbar-thumb { background: var(--border); }

.log-entry {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  align-items: start;
  animation: fadeUp 0.12s ease;
}

@keyframes fadeUp {
  from { opacity:0; transform:translateY(4px); }
  to   { opacity:1; transform:none; }
}

.log-time {
  font-size: 9px;
  color: var(--text-low);
  padding-top: 3px;
  text-align: right;
  letter-spacing: 0.3px;
  opacity: 0.7;
}

.log-text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-mid);
  white-space: pre-wrap;
  word-break: break-word;
}

.log-text code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--card);
  color: var(--text-hi);
  padding: 1px 5px;
  border: 1px solid var(--border);
}

.log-text strong { color: var(--text-hi); font-weight: 500; }

.log-opr   .log-time { color: var(--accent); opacity: 1; }
.log-opr   .log-text { color: var(--text-hi); }
.log-sys   .log-text { color: var(--text-low); font-size: 11px; font-style: italic; }
.log-event .log-text { color: var(--text-hi); font-weight: 500; }
.log-event .log-time { color: var(--text-mid); opacity: 1; }

/* ── PROMPT BOX ───────────────────────────────────────────── */
#prompt-box {
  display: none;
  margin: 0 24px 10px;
  padding: 11px 15px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 2px solid var(--c3);
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-hi);
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: 140px;
  overflow-y: auto;
}

/* ── INPUT BAR ────────────────────────────────────────────── */
.input-bar {
  display: flex;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.input-prefix {
  display: flex;
  align-items: center;
  padding: 0 16px;
  color: var(--text-low);
  font-size: 9px;
  letter-spacing: 3px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

#op-input {
  flex: 1;
  background: var(--surface);
  border: none;
  color: var(--text-hi);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 17px 20px;
  outline: none;
  transition: background 0.15s;
  resize: none;
  overflow-y: auto;
  min-height: 52px;
  max-height: 160px;
  line-height: 1.5;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#op-input:not(:disabled):focus { background: var(--card); }
#op-input::placeholder          { color: var(--th-text-faint); opacity: 1; }
#op-input:disabled              { opacity: 0.3; cursor: not-allowed; }

#send-btn {
  background: var(--accent);
  color: var(--th-accent-ink);
  border: none;
  border-left: 1px solid var(--border);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 3px;
  padding: 0 22px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) { background: var(--th-accent-hover); }
#send-btn:disabled              { opacity: 0.2; cursor: not-allowed; }

/* ── TWO-COLUMN LAYOUT ────────────────────────────────────── */
#main-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.main-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── LEFT PANEL ───────────────────────────────────────────── */
.left-panel {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 5px;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
  overflow-y: auto;
}

.left-panel.collapsed {
  width: 0 !important;
  padding: 0 !important;
  opacity: 0;
  pointer-events: none;
}

.left-panel-section {
  display: flex;
  flex-direction: column;
}

.left-panel-label {
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--text-low);
  text-transform: uppercase;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* pairs of buttons side by side */
.ticker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.ticker-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-low);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 8px 8px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, color 0.2s, background 0.2s, box-shadow 0.2s;
}

.ticker-btn:hover {
  border-color: var(--c3);
  color: var(--text-mid);
  background: var(--card);
}

.ticker-btn:active { background: var(--th-panel); }

.ticker-btn.ticker-active {
  border-color: var(--text-hi);
  color: var(--text-hi);
  background: var(--card);
  box-shadow:
    inset 0 1px 0 rgba(233,238,227,0.15),
    0 0 12px var(--th-accent-dim);
}

/* ── BOTTOM STATS (join counter + winrate above input) ────── */
#bottom-stats {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  min-height: 32px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow: hidden;
}

#winrate-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.wr-header {
  font-size: 8px;
  letter-spacing: 3px;
  color: var(--text-low);
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

#winrate-body {
  display: flex;
  flex-direction: row;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  flex: 1;
  min-width: 0;
  padding: 2px 0;
}

.wr-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  transition: border-color 0.2s;
}

.wr-row.wr-top {
  border-color: var(--c3);
  background: var(--card);
}

.wr-meta {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
}

.wr-tag {
  font-size: 9px;
  color: var(--text-low);
  letter-spacing: 1px;
  flex-shrink: 0;
}

.wr-name {
  font-size: 10px;
  color: var(--text-hi);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.wr-stats {
  font-size: 9px;
  color: var(--text-low);
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.wr-bar-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 70px;
}

.wr-bar {
  height: 3px;
  background: var(--c3);
  flex-shrink: 0;
  transition: width 0.4s ease;
  min-width: 4px;
}

.wr-top .wr-bar { background: var(--text-hi); }

.wr-pct {
  font-size: 10px;
  color: var(--text-mid);
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.wr-top .wr-pct { color: var(--text-hi); font-weight: 500; }

.wr-placeholder {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-low);
  text-transform: uppercase;
  opacity: 0.5;
  white-space: nowrap;
}



/* ── RIGHT PANEL ──────────────────────────────────────────── */
.right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── TOGGLE BUTTON ────────────────────────────────────────── */
.panel-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-low);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}

.panel-toggle:hover {
  border-color: var(--c3);
  color: var(--text-mid);
}

/* ── MOBILE ───────────────────────────────────────────────── */
@media (max-width: 480px) {
  .h-sub, .h-sep { display: none; }
  .header { padding: 0 16px; height: 48px; }

  #main-screen {
    height: 100%;
    min-height: -webkit-fill-available;
    min-height: fill-available;
  }

  body {
    height: 100%;
    min-height: -webkit-fill-available;
    overflow: hidden;
  }

  html { height: -webkit-fill-available; }

  .right-panel { position: relative; height: 100%; }

  #bottom-stats {
    position: fixed;
    bottom: 52px; left: 0; right: 0;
    z-index: 49;
    border-top: 1px solid var(--c3);
    padding: 4px 10px;
    min-height: 28px;
    background: var(--surface);
  }

  #log-box {
    padding: 12px 14px;
    padding-bottom: 100px;
  }

  .input-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 50;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .input-prefix { padding: 0 10px; font-size: 8px; }

  #op-input {
    font-size: 16px;
    padding: 14px 14px;
    -webkit-appearance: none;
    min-height: 50px;
    max-height: 120px;
  }

  #send-btn {
    padding: 0 14px;
    font-size: 10px;
    min-width: 60px;
    min-height: 50px;
  }

  #prompt-box {
    position: fixed;
    bottom: 84px; left: 0; right: 0;
    margin: 0;
    border-left: none; border-right: none;
    border-top: 1px solid var(--c3);
    border-bottom: none;
    border-radius: 0;
    z-index: 49;
    max-height: 90px;
    padding: 10px 14px;
    font-size: 11px;
  }

  /* Left panel fullscreen slide-in on mobile */
  .left-panel {
    position: fixed;
    inset: 0;
    width: 100vw !important;
    height: 100%;
    min-height: -webkit-fill-available;
    z-index: 100;
    background: var(--bg);
    padding: 28px 20px !important;
    overflow-y: auto;
    opacity: 1;
    display: flex;
    transform: translateX(-100%);
    transition: transform 0.25s ease, opacity 0.25s ease;
  }

  .left-panel.mobile-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: all;
  }

  .left-panel.collapsed {
    width: 100vw !important;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-100%);
  }

  .ticker-btn     { padding: 14px 8px; font-size: 12px; }
  .panel-close-mobile { display: flex; }
  .log-entry { gap: 10px; }
  .log-text  { font-size: 12px; }
  .log-time  { font-size: 8px; }
}

@media (min-width: 481px) {
  .panel-close-mobile { display: none !important; }
}
