[hidden] { display: none !important; }

:root {
  --online: #2f9e5b;
  --bg: #f6f2ee;
  --surface: #ffffff;
  --surface-2: #efe8e2;
  --ink: #241d2b;
  --ink-2: #6b6274;
  --line: #e2d9d1;
  --accent: #b2507a;
  --accent-ink: #ffffff;
  --mine: #b2507a;
  --theirs: #ece5ef;
  --hidden: #f3e7c9;
  --good: #3d8c6a;
  --warn: #c07a1f;
  --bad: #b3423b;
  --radius: 18px;
  font-family: Inter, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131c;
    --surface: #211b28;
    --surface-2: #2a2333;
    --ink: #efe9f3;
    --ink-2: #a79cb2;
    --line: #362d40;
    --accent: #e07aa6;
    --accent-ink: #1b1622;
    --mine: #c45a89;
    --theirs: #2f2738;
    --hidden: #3a3123;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); display: flex; flex-direction: column; height: 100dvh; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { font-family: Fraunces, serif; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.brand span { color: var(--accent); }
#game-select { margin-left: auto; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; cursor: pointer; color: var(--ink-2); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }

.alert { padding: 10px 16px; background: var(--hidden); border-bottom: 1px solid var(--line); font-size: 14px; }

main { flex: 1; min-height: 0; }
.view { display: none; height: 100%; }
.view.active { display: block; }

.split { display: grid; grid-template-columns: 300px 1fr; height: 100%; }
.list { border-right: 1px solid var(--line); overflow-y: auto; background: var(--surface); }
.conv {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: pointer;
}
.conv:hover, .conv.active { background: var(--surface-2); }
.conv .top { display: flex; align-items: baseline; gap: 8px; }
.conv .name { font-weight: 600; }
.conv .time { margin-left: auto; font-size: 12px; color: var(--ink-2); }
.conv .preview { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .badge { background: var(--accent); color: var(--accent-ink); font-size: 12px; border-radius: 999px; padding: 0 7px; }
.conv .tag { font-size: 11px; color: var(--ink-2); background: var(--hidden); border-radius: 6px; padding: 1px 6px; width: fit-content; }

.thread { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.thread-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.thread-title { font-weight: 600; }
.back { display: none; border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; padding: 0 6px 0 0; }

.bubbles { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.empty { color: var(--ink-2); margin: auto; text-align: center; max-width: 320px; }
.day { align-self: center; font-size: 12px; color: var(--ink-2); margin: 12px 0 6px; }
.bubble {
  max-width: min(72%, 520px); padding: 8px 12px; border-radius: var(--radius); line-height: 1.4;
  white-space: pre-wrap; overflow-wrap: anywhere; background: var(--theirs); align-self: flex-start;
}
.bubble.mine { background: var(--mine); color: #fff; align-self: flex-end; }
.bubble .meta { display: block; font-size: 11px; opacity: 0.7; margin-top: 2px; text-align: right; }
.bubble .who { display: block; font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.bubble.mine .who { color: #fff; }
.reader .bubble.hidden-from-lila { box-shadow: inset 3px 0 0 var(--warn); }

.typing { display: flex; gap: 4px; padding: 0 16px 10px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; background: var(--bg); max-height: 140px; }
.composer button { border: 0; background: var(--accent); color: var(--accent-ink); width: 42px; border-radius: 50%; cursor: pointer; font-size: 16px; }

.console { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; padding: 16px; overflow-y: auto; height: 100%; align-content: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h2 { font-family: Fraunces, serif; font-weight: 600; font-size: 19px; margin: 0 0 12px; }
.card h3 { font-size: 14px; margin: 16px 0 8px; color: var(--ink-2); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.card input, .card select, .card textarea { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); width: 100%; }
.card button { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.note-form { display: flex; flex-direction: column; gap: 8px; }
.hint { color: var(--ink-2); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi .label { font-size: 12px; color: var(--ink-2); }
.kpi .value { font-family: Fraunces, serif; font-size: 26px; font-weight: 600; }
.kpi .value.warn { color: var(--warn); }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); margin: 14px 0 6px; overflow: hidden; }
.meter div { height: 100%; background: var(--accent); width: 0; transition: width 0.4s; }
.breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 12px; }
.breakdown h3 { margin-top: 0; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; margin-bottom: 6px; }
.bar .track { grid-column: 1 / -1; height: 5px; border-radius: 999px; background: var(--surface-2); }
.bar .fill { height: 100%; border-radius: 999px; background: var(--accent); }

.notes, .threads, .scheduled, .events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.notes li, .threads li, .scheduled li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.notes li { display: flex; gap: 8px; align-items: start; }
.notes li .text { flex: 1; }
.notes li button { background: transparent; color: var(--ink-2); padding: 0 4px; }
.small { font-size: 12px; color: var(--ink-2); }
.events li { font-size: 13px; display: grid; grid-template-columns: 110px 170px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.events code { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; color: var(--ink-2); }

.card button.secondary { background: var(--surface-2); color: var(--ink); }
.switch { display: flex; gap: 10px; align-items: center; margin-top: 12px; font-size: 14px; cursor: pointer; }
.switch input { width: auto; accent-color: var(--accent); }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 24px; }
dialog form { display: flex; flex-direction: column; gap: 10px; min-width: 260px; }
dialog h2 { font-family: Fraunces, serif; margin: 0; }
dialog input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--bg); }
dialog button { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 9px; cursor: pointer; }

@media (max-width: 720px) {
  .topbar { flex-wrap: nowrap; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    justify-content: space-around; border-radius: 0; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tab { flex: 1; padding: 10px 0; font-size: 15px; }
  .tab.active { box-shadow: none; background: var(--surface-2); }
  main { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  body.in-thread .tabs { display: none; }
  body.in-thread main { padding-bottom: 0; }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .composer textarea, .card input, .card select, .card textarea, dialog input { font-size: 16px; }
  .console { padding: 12px; gap: 12px; grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .split .thread { display: none; }
  .split.open .list { display: none; }
  .split.open .thread { display: flex; }
  .back { display: block; }
  .bubble { max-width: 85%; }
  .events li { grid-template-columns: 1fr; gap: 2px; }
  #game-select { margin-left: auto; max-width: 55vw; }
}

.bubble.photo { padding: 4px; }
.bubble.photo img { display: block; max-width: min(260px, 70vw); max-height: 340px; border-radius: 14px; cursor: zoom-in; }
.bubble.photo .meta { padding: 0 6px 2px; }
.lightbox { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgb(0 0 0 / 0.85); cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 90vh; border-radius: 8px; }

.token { word-break: break-all; user-select: all; background: var(--surface-2); padding: 8px 10px; border-radius: 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; max-height: 70vh; overflow-y: auto; }
.photo-item { margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.photo-item img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; cursor: zoom-in; }
.photo-item figcaption { display: flex; flex-direction: column; gap: 4px; padding: 8px; font-size: 12px; color: var(--ink-2); }
.photo-item figcaption strong { color: var(--ink); }
.photo-item.used img { opacity: 0.6; }
.photo-item.disabled { opacity: 0.4; }

.thread-heading { display: flex; flex-direction: column; min-width: 0; }
.thread-sub { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-sub.on { color: var(--online); }
.conv .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; align-self: center; }
.conv .dot.on { background: var(--online); }
