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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --accent: #FF3B3B;
  --accent2: #ff5555;
  --text: #ffffff;
  --muted: #888888;
  --dim: #444444;
  --border: #2a2a2a;
  --gold: #FFD700;
  --nav-h: 60px;
  --screen-pad-x: 20px;
  --screen-pad-top: 28px;
  --screen-pad-btm: 12px;
}

html, body {
  height: 100%;
  background: #050505;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  overflow: hidden;
}

#app {
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ── Bottom Nav ── */
#bottom-nav {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: #0f0f0f;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  transition: opacity 0.2s;
}
#bottom-nav.hidden { opacity: 0; pointer-events: none; }

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: color 0.15s, transform 0.1s;
  font-size: 22px;
}
.nav-btn span.lbl { font-size: 10px; font-family: 'DM Sans', sans-serif; font-weight: 500; }
.nav-btn.active { color: var(--accent); }
.nav-btn:active { transform: scale(0.88); }

/* ── Splash ── */
#screen-splash {
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
}
.splash-rose {
  font-size: 76px;
  animation: rosePulse 1.4s ease-in-out infinite;
  display: block;
  line-height: 1;
}
@keyframes rosePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18) rotate(5deg); }
}
.splash-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 52px;
  letter-spacing: -2px;
}
.splash-tag { font-size: 13px; color: var(--muted); letter-spacing: 0.4px; }

/* ── Auth ── */
#screen-auth { padding: var(--screen-pad-top) var(--screen-pad-x) 28px; }
.auth-logo-row {
  text-align: center;
  margin-bottom: 20px;
}
.auth-logo-icon { font-size: 44px; display: block; margin-bottom: 4px; }
.auth-logo-name {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 30px;
}
.auth-tabs {
  display: flex;
  background: var(--surface);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 18px;
}
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  padding: 9px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.auth-tab.active { background: var(--accent); color: #fff; }

.fg { margin-bottom: 12px; }
.fg label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.fg input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.fg input:focus { border-color: var(--accent); }
.fg input::placeholder { color: var(--dim); }

.fg input.emoji-input {
  font-size: 22px;
  cursor: pointer;
  caret-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.fg input.emoji-input:focus { outline: none; border-color: var(--accent); }

/* Emoji picker (native OS “emoji only” keyboard isn’t available on the web; tap opens this sheet) */
.emoji-picker-root {
  position: absolute;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
}
.emoji-picker-root.open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
.emoji-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.emoji-picker-sheet {
  position: relative;
  width: 100%;
  max-height: min(52vh, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}
.emoji-picker-head {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  margin-bottom: 12px;
  color: var(--muted);
}
.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  max-height: 38vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
}
.emoji-picker-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
  padding: 0;
  border: none;
  background: var(--surface2);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s;
}
.emoji-picker-btn:active { transform: scale(0.92); background: var(--border); }
.emoji-picker-done { width: 100%; margin-top: 2px; }

.auth-err {
  background: rgba(255,59,59,.12);
  border: 1px solid rgba(255,59,59,.3);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 12px;
  display: none;
}
.auth-err.show { display: block; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.do-shake { animation: shake 0.38s ease; }

/* ── Shared Buttons ── */
.btn-red {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  letter-spacing: 0.2px;
  transition: transform 0.1s ease, background 0.15s;
}
.btn-red:active { transform: scale(0.96); }
.btn-red:hover { background: var(--accent2); }
.btn-red:disabled { opacity: 0.35; cursor: not-allowed; transform: none !important; }
.btn-red.pulsing { animation: bPulse 1.6s ease-in-out infinite; }
@keyframes bPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,59,59,.4); }
  50% { box-shadow: 0 0 0 14px rgba(255,59,59,0); }
}

.btn-ghost {
  width: 100%;
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 13px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s;
}
.btn-ghost:active { transform: scale(0.96); }
.btn-ghost:hover { border-color: var(--muted); color: var(--text); }

.back-btn {
  width: 38px; height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.back-btn:active { transform: scale(0.88); }

/* ── Home ── */
#screen-home {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: var(--screen-pad-top) var(--screen-pad-x) calc(var(--nav-h) + var(--screen-pad-btm));
  justify-content: flex-start;
  gap: 18px;
}
.home-top { text-align: center; flex-shrink: 0; }
.home-greeting { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.home-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 40px;
  text-align: center;
  margin-bottom: 0;
  letter-spacing: -1px;
  line-height: 1.05;
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
}
.home-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.action-card {
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 0 18px;
  min-height: 72px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.action-card:active { transform: scale(0.97); }
.action-card:hover { border-color: var(--accent); background: var(--surface2); }
.action-icon { font-size: 28px; }
.action-text { flex: 1; }
.action-arrow { color: var(--dim); font-size: 18px; }

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex-shrink: 0;
}
.stat-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 14px 12px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; font-weight: 500; line-height: 1.25; }
.stat-val {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 26px;
  color: var(--accent);
  line-height: 1.1;
  word-break: break-word;
}

/* ── Paste Screen (wireframe: upload block + text block + footer actions) ── */
#screen-paste {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: var(--screen-pad-top) var(--screen-pad-x) calc(var(--nav-h) + var(--screen-pad-btm));
}
.screen-hdr {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
  flex-shrink: 0;
}
.paste-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen-hdr-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 22px;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 10px;
  position: relative;
  user-select: none;
  flex: 0 0 auto;
  min-height: min(36vh, 220px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.upload-zone:hover, .upload-zone.drag { border-color: var(--accent); background: rgba(255,59,59,.04); }
.upload-icon { font-size: 28px; margin-bottom: 4px; }
.upload-main { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.upload-sub { font-size: 12px; color: var(--dim); }
#file-input { display: none; }

.divider {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 0;
  color: var(--dim); font-size: 12px;
}
.divider::before,.divider::after { content:''; flex:1; height:1px; background:var(--border); }

.textarea-wrap { position: relative; margin-bottom: 4px; flex: 1; display: flex; flex-direction: column; min-height: 120px; }
.text-area {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  resize: none;
  outline: none;
  min-height: 120px;
  flex: 1;
  line-height: 1.55;
  transition: border-color 0.2s;
}
.text-area:focus { border-color: var(--accent); }
.text-area::placeholder { color: var(--dim); }
.word-count { font-size: 12px; color: var(--dim); text-align: right; margin-bottom: 10px; }

.file-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: none;
  flex-shrink: 0;
}
.file-card.show { display: block; }
.file-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.file-left { display: flex; align-items: center; gap: 10px; }
.file-emoji { font-size: 22px; }
.file-nm { font-size: 14px; font-weight: 600; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sz { font-size: 12px; color: var(--muted); }
.dismiss {
  background: none; border: none; color: var(--dim);
  font-size: 16px; cursor: pointer; padding: 4px; line-height: 1;
}
.prog-bg { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.prog-fill { height: 100%; width: 100%; background: var(--accent); border-radius: 2px; }

.paste-btns {
  display: flex;
  flex-direction: row;
  gap: 10px;
  flex-shrink: 0;
  margin-top: 10px;
  padding-top: 4px;
}
.paste-btns .btn-red,
.paste-btns .btn-ghost {
  width: auto;
  flex: 1;
  min-width: 0;
  padding: 14px 12px;
  font-size: 15px;
}
.paste-btns .btn-red { flex: 1.15; }

/* ── Loading (wireframe: centered column, breathing room top/bottom) ── */
#screen-loading {
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: var(--screen-pad-top) var(--screen-pad-x) 32px;
}
.loading-back { position: absolute; top: 14px; left: var(--screen-pad-x); }
.loading-gif {
  width: 100%; max-width: 320px;
  border-radius: 14px;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
}
.load-bar-wrap { width: 100%; max-width: 320px; }
.load-bar-bg { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.load-bar-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 3px; transition: width 3s ease-in-out; }
.load-txt { font-size: 15px; color: var(--muted); text-align: center; min-height: 22px; }

/* ── Results (wireframe: hero centered, actions pinned near bottom) ── */
#screen-results {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 20px var(--screen-pad-x) 24px;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0;
}
.res-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
}
.res-gif {
  width: 100%;
  max-width: 340px;
  max-height: 280px;
  border-radius: 16px;
  display: block;
  margin-bottom: 14px;
  object-fit: cover;
}
.score-big {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 48px;
  color: var(--accent);
  line-height: 1;
  text-align: center;
  margin-bottom: 6px;
}
.tier-name {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 20px;
  text-align: center;
  margin-bottom: 8px;
}
.res-quote {
  font-style: italic;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  max-width: 300px;
  line-height: 1.5;
  margin-bottom: 0;
}
.res-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 360px;
  align-self: center;
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 16px;
}

/* ── Confetti ── */
.confetti {
  position: absolute;
  top: -16px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 9999;
  animation: cFall linear forwards;
}
@keyframes cFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(780deg); opacity: 0; }
}

/* ── Friends / Leaderboard (wireframe: podium ~upper third, dense list) ── */
#screen-friends { padding: var(--screen-pad-top) var(--screen-pad-x) calc(var(--nav-h) + var(--screen-pad-btm)); }
.lb-head-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 24px;
  margin-bottom: 0;
}
.lb-head-sub { font-size: 13px; color: var(--muted); margin-bottom: 12px; }

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 30vh;
  max-height: 38vh;
}
.pod-item { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.pod-item.p1 { order: 2; }
.pod-item.p2 { order: 1; }
.pod-item.p3 { order: 3; }
.pod-crown { font-size: 18px; line-height: 1; visibility: hidden; }
.pod-item.p1 .pod-crown { visibility: visible; }
.pod-av {
  border-radius: 50%;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--border);
  font-size: 22px;
  width: 50px; height: 50px;
}
.pod-item.p1 .pod-av { width: 64px; height: 64px; font-size: 30px; border-color: var(--gold); border-width: 2.5px; }
.pod-nm {
  font-size: 12px; font-weight: 600; text-align: center;
  max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pod-sc { font-size: 11px; color: var(--accent); font-weight: 600; }
.pod-pos { font-family: 'Syne', sans-serif; font-weight: 800; font-size: 20px; }
.pod-item.p1 .pod-pos { color: var(--gold); }
.pod-item.p2 .pod-pos { color: #c0c0c0; }
.pod-item.p3 .pod-pos { color: #cd7f32; }

.lb-section-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.rank-list { display: flex; flex-direction: column; }
.rank-item { border-bottom: 1px solid var(--border); }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.rank-num { font-family:'Syne',sans-serif; font-weight:700; font-size:15px; color:var(--dim); width:22px; text-align:center; flex-shrink:0; }
.rank-av { width:38px; height:38px; border-radius:50%; background:var(--surface2); display:flex; align-items:center; justify-content:center; font-size:18px; flex-shrink:0; }
.rank-info { flex:1; min-width:0; }
.rank-name { font-size:14px; font-weight:600; }
.rank-time { font-size:11px; color:var(--dim); }
.rank-right { display:flex; align-items:center; gap:7px; flex-shrink:0; }
.badge {
  font-size: 10px; font-weight: 600;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255,59,59,.13);
  color: var(--accent);
  white-space: nowrap;
}
.clown-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.clown-btn:hover { border-color: var(--accent); color: var(--accent); }

.cmt-section { display:none; padding: 0 0 14px 34px; }
.cmt-section.open { display:block; }
.cmt-list { display:flex; flex-direction:column; gap:5px; margin-bottom:9px; }
.cmt-bubble {
  font-size:13px; color:var(--muted);
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 10px;
  line-height: 1.4;
}
.cmt-bubble strong { color: var(--text); }
.cmt-form { display:flex; gap:7px; }
.cmt-input {
  flex:1; background:var(--surface); border:1px solid var(--border);
  border-radius:10px; padding:8px 12px; color:var(--text);
  font-family:'DM Sans',sans-serif; font-size:13px; outline:none;
}
.cmt-input:focus { border-color: var(--accent); }
.cmt-send {
  background:var(--accent); border:none; border-radius:10px;
  padding:8px 14px; color:#fff;
  font-family:'DM Sans',sans-serif; font-weight:600; font-size:13px;
  cursor:pointer; transition:transform 0.1s;
}
.cmt-send:active { transform:scale(0.94); }

.empty-lb { text-align:center; color:var(--muted); font-size:15px; padding:28px 0; }

/* ── Settings ── */
#screen-settings { padding: var(--screen-pad-top) var(--screen-pad-x) calc(var(--nav-h) + var(--screen-pad-btm)); }
.screen-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 24px;
  margin-bottom: 16px;
}

.settings-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 18px;
}
.settings-avatar {
  font-size: 34px;
  width: 62px; height: 62px;
  background: var(--surface2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 2px solid var(--border);
}
.settings-meta { flex: 1; min-width: 0; }
.settings-dname {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-uname { font-size: 13px; color: var(--muted); margin-top: 3px; }

.settings-section { margin-bottom: 18px; }
.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.btn-logout {
  width: 100%;
  background: rgba(255,59,59,.08);
  color: var(--accent);
  border: 1.5px solid rgba(255,59,59,.25);
  border-radius: 12px;
  padding: 13px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-align: center;
}
.btn-logout:active { transform: scale(0.96); }
.btn-logout:hover { background: rgba(255,59,59,.18); }

/* ── Toast ── */
.toast {
  position: absolute;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 500;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

::-webkit-scrollbar { width:0; }
