:root {
  --bg: #0b1d2e;
  --panel: #12304a;
  --panel-2: #1a3d5c;
  --text: #e8f1f8;
  --muted: #8aa6bf;
  --accent: #ff7a6b;
  --accent-2: #ffb199;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* Pin the page so only #messages scrolls; otherwise iOS Safari scrolls the body too. */
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--vh, 100dvh);
  padding-bottom: env(safe-area-inset-bottom);
  font: 15px/1.45 system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; background: var(--accent); color: #1b0b08; padding: 8px 14px; font-weight: 600; }
button:hover { background: var(--accent-2); }
button.link { background: none; color: var(--accent-2); padding: 0; font-weight: 600; }
button.link:hover { text-decoration: underline; }
/* iOS Safari zooms on focus when a field's font-size is under 16px. */
input, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--panel-2); border: 1px solid #2a5478; border-radius: 8px; padding: 8px 10px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: #ff8a80; margin: 0; font-size: 14px; }
a { color: var(--accent-2); }
.gate textarea { width: 100%; resize: none; }
.gate p { margin: 0; }

header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid #1f4566; }
header h1 { font-size: 18px; margin: 0; }
.header-right { display: flex; gap: 16px; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; max-width: 760px; width: 100%; margin: 0 auto; }
main[hidden] { display: none; }
#messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 12px 16px; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .05em; }
.msg { margin: 8px 0; padding: 8px 12px; background: var(--panel); border-radius: 10px; max-width: 90%; }
.msg.mine { background: var(--panel-2); margin-left: auto; }
.msg.champ { background: linear-gradient(135deg, #3a2e0a, #2a2208); border: 1px solid #e6b422; box-shadow: 0 0 12px rgba(230, 180, 34, .25); }
.msg.champ .name { color: #ffd54a; }
.crown { display: none; }
.msg.champ .crown { display: inline; cursor: default; }
.meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.body { white-space: pre-wrap; word-wrap: break-word; }
.result-head { color: var(--muted); font-size: 13px; }
.result-score { font-size: 24px; font-weight: 700; }
.result-emojis { font-size: 22px; letter-spacing: 2px; }
.result .body { margin-top: 6px; }

#composer { display: flex; gap: 8px; padding: 10px 16px 16px; }
#composer textarea { flex: 1; resize: none; }

.overlay { position: fixed; inset: 0; background: rgba(5, 14, 24, .85); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay[hidden] { display: none; }
.card { background: var(--panel); border-radius: 14px; padding: 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; font-size: 18px; }
.gate { text-align: center; align-items: center; }
.big { font-size: 22px; padding: 16px 40px; border-radius: 999px; }

.stats { max-width: 560px; max-height: 90vh; overflow-y: auto; position: relative; }
.stats h3 { margin: 12px 0 4px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.close { position: absolute; top: 10px; right: 12px; background: none; color: var(--muted); font-size: 22px; padding: 0 6px; }
.close:hover { background: none; color: var(--text); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #1f4566; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 10px; text-align: center; }
.stat-value { font-size: 20px; font-weight: 700; }
.history { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; max-width: 32px; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.bar-label { font-size: 9px; color: var(--muted); overflow: hidden; }
.dist-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.dist-emoji { font-size: 20px; width: 28px; text-align: center; }
.dist-track { flex: 1; height: 12px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.dist-fill { height: 100%; background: var(--accent); }
.dist-n { font-size: 13px; color: var(--muted); width: 72px; text-align: right; }

.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--panel-2); padding: 10px 16px; border-radius: 8px; z-index: 20; }
