@import url('tokens.css');
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Shell ──────────────────────────────────── */
.shell {
  flex: 1;
  width: 100%;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}
.inner {
  width: 100%;
  max-width: var(--content-max-mobile);
  margin: 0 auto;
  padding: env(safe-area-inset-top, 12px) 16px 24px;
}
@media (min-width: 768px) {
  .shell { padding-top: 56px; padding-bottom: 40px; }
  .inner { max-width: var(--content-max-desktop); padding: 24px 32px 40px; }
}

/* ── Nav (desktop top) ─────────────────────── */
.topnav {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--bg3);
  padding: 0 24px;
  align-items: center;
  gap: 20px;
  z-index: 100;
}
.topnav .brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}
.topnav .brand span { color: var(--green); }
.topnav .links { display: flex; gap: 4px; flex: 1; }
.topnav a {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  border-radius: var(--radius-sm);
}
.topnav a:hover { color: var(--text); text-decoration: none; background: var(--bg3); }
.topnav a.active { color: var(--green); background: var(--bg3); }
@media (min-width: 768px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
}

/* ── Nav (mobile bottom) ───────────────────── */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--bg3);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}
.bottomnav a {
  flex: 1;
  height: var(--nav-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text3);
  font-size: 10px;
}
.bottomnav a:hover { text-decoration: none; }
.bottomnav a.active { color: var(--green); }
.bottomnav .icon { font-size: 20px; line-height: 1; }
.bottomnav .label { font-size: 10px; }

/* ── Buttons ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 18px;
  font-size: 17px;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: opacity 0.1s, transform 0.1s;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn:disabled { opacity: 0.3; pointer-events: none; }
.btn-block { width: 100%; }
.btn-start   { background: var(--green); color: #fff; }
.btn-stop    { background: var(--red);   color: #fff; }
.btn-save    { background: var(--blue);  color: #fff; font-size: 15px; }
.btn-reset   { background: var(--bg3);   color: var(--text2); font-size: 15px; }
.btn-discard { background: var(--bg3);   color: var(--text2); font-size: 15px; }

.btn-icon {
  background: none;
  border: none;
  color: var(--green);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 2px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.btn-icon:active { opacity: 0.7; }

/* ── Forms ─────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.form-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  font-family: inherit;
}
.form-input:focus { outline: none; border-color: var(--green); }
.form-input.field-error { border-color: var(--red); }
.form-error { font-size: 12px; color: var(--red); margin-top: 6px; }

/* ── Tabs ──────────────────────────────────── */
.tab-row {
  display: flex;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 14px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  background: none;
  color: var(--text2);
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.tab-btn.active { background: var(--bg3); color: var(--text); }

/* ── Cards ─────────────────────────────────── */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 16px;
}
a.card { color: inherit; }
a.card:hover { text-decoration: none; border-color: var(--border2); }

/* ── Empty state & utilities ───────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text3); font-size: 14px; line-height: 1.6; }
h1 { font-size: 22px; font-weight: 600; margin-bottom: 12px; }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 10px; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.muted { color: var(--text2); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tabular { font-variant-numeric: tabular-nums; }
.sep { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.hidden { display: none !important; }

/* ── Stats ─────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.stat-val { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.stat-lbl { font-size: 11px; color: var(--text2); margin-top: 4px; }

/* ── Tags ──────────────────────────────────── */
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
}
.tag.green { background: rgba(29,158,117,0.15); color: var(--green); border-color: var(--green-dark); }
.tag.red   { background: rgba(216,90,48,0.15);  color: var(--red);   border-color: var(--red-dark); }

/* ── History cards ─────────────────────────── */
.hist-card { background: var(--bg2); border-radius: var(--radius); border: 1px solid var(--border); padding: 14px 16px; }
.hist-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hist-title { font-size: 15px; font-weight: 600; flex: 1; word-break: break-word; }
.hist-date { font-size: 11px; color: var(--text3); white-space: nowrap; }
.hist-meta { font-size: 13px; color: var(--text2); margin-top: 6px; line-height: 1.5; }
.hist-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.hist-chip {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
}
.hist-chip.best  { background: rgba(29,158,117,0.15); color: var(--green); border-color: var(--green-dark); }
.hist-chip.worst { background: rgba(216,90,48,0.15);  color: var(--red);   border-color: var(--red-dark); }
.type-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
  margin-right: 6px;
}
.type-free  { background: rgba(55,138,221,0.18); color: var(--blue); }
.type-drill { background: rgba(29,158,117,0.18); color: var(--green); }

/* ── Ranking list ──────────────────────────── */
.rank-list { list-style: none; padding: 0; }
.rank-list li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.rank-list li:last-child { border-bottom: none; }
.rank-num { min-width: 28px; color: var(--text2); }
.rank-name { flex: 1; }
.rank-time { min-width: 80px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── Shortcode display ─────────────────────── */
.shortcode-display {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 4px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin-bottom: 14px;
}
.qr-wrap {
  display: inline-block;
  padding: 8px;
  background: var(--bg2);
  border-radius: var(--radius);
}
.qr-wrap img { display: block; }
