/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 60px;
  padding: 0 22px;
  border-radius: var(--r-pill);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), background var(--speed);
}
.btn:active { transform: translateY(1px) scale(.996); }
.btn-block { width: 100%; }
.btn-lg { height: 61px; }
.btn-sm { height: 44px; padding: 0 16px; font-size: 15px; border-radius: 14px; gap: 6px; }
.btn-primary, .btn-gold {
  background: linear-gradient(180deg, #F1C976 0%, #DFAB46 52%, #BC882E 100%);
  color: var(--on-gold);
  box-shadow: var(--gold-glow), inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -2px 0 rgba(120, 82, 20, .35);
}
.btn-primary:active, .btn-gold:active {
  box-shadow: 0 4px 14px rgba(228, 176, 74, .22), inset 0 1px 0 rgba(255, 255, 255, .4);
}
.btn:disabled { opacity: .42; box-shadow: none; pointer-events: none; }
.btn-outline {
  height: 56px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}
.btn-outline.is-on { border-color: var(--gold-border-3); color: var(--gold-text); background: #1D1C19; }
.btn-dark { background: #1B1D22; border: 1px solid var(--border); color: var(--text); font-size: 16px; font-weight: 600; height: 56px; }
.btn-soft { background: #1B1D22; border: 1px solid var(--border); color: var(--text-2); font-size: 15px; font-weight: 600; height: 48px; }
.btn-ghost { background: none; color: var(--text-2); font-size: 15px; font-weight: 600; height: 44px; }
.btn-danger { background: var(--bad-bg); border: 1px solid #5A3540; color: #FF8B96; font-size: 16px; height: 56px; }
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: #1B1D22;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Ivory tiles ---------- */
.tile {
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--tile-1) 0%, var(--tile-2) 100%);
  color: var(--tile-ink);
  font-weight: 800;
  line-height: 1;
  border-radius: 28%;
  user-select: none;
  box-shadow:
    0 4px 0 var(--tile-edge),
    0 12px 22px rgba(0, 0, 0, .45),
    inset 0 1.5px 0 rgba(255, 255, 255, .9),
    inset 0 -6px 10px rgba(188, 168, 128, .22);
}
.tile-sm { width: 42px; height: 42px; font-size: 21px; border-radius: 11px; box-shadow: 0 3px 0 var(--tile-edge), 0 8px 14px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.9); }
.tile-md { width: 48px; height: 48px; font-size: 25px; border-radius: 14px; }
.tile-lg { width: 101px; height: 101px; font-size: 62px; border-radius: 28px; }
.tile-field { width: 31px; height: 31px; font-size: 17px; border-radius: 9px; box-shadow: 0 3px 0 var(--tile-edge), 0 6px 10px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.85); }
.tile-ghost {
  background: var(--border-soft);
  color: var(--placeholder);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.tile-halo { box-shadow: 0 4px 0 var(--tile-edge), 0 18px 40px rgba(0,0,0,.5), 0 0 60px rgba(228,176,74,.16), inset 0 1.5px 0 rgba(255,255,255,.9); }
.tile-tilt-1 { transform: rotate(-4deg); }
.tile-tilt-2 { transform: rotate(4deg); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
}
.card-flat { background: var(--surface-2); }
.card-row { display: flex; align-items: center; gap: 12px; }
.card-hero {
  background: linear-gradient(180deg, var(--hero-a) 0%, var(--hero-b) 100%);
  border: 1px solid var(--hero-border);
  border-radius: var(--r-xl);
}
.card-duel {
  background: linear-gradient(180deg, var(--duel-a) 0%, var(--duel-b) 100%);
  border: 1px solid var(--duel-border);
  border-radius: var(--r-md2);
}
.card-soft { background: var(--surface-4); border: 1px solid var(--border); border-radius: var(--r-md2); }

/* ---------- Chips / segmented / stepper ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 27px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: background var(--speed), border-color var(--speed), color var(--speed);
}
.chip.is-on { background: #211F1A; border-color: #796030; color: var(--gold-text); }
.chip.is-off { color: var(--muted); }
.chip-gold { background: #27241C; border-color: #5E4E2F; color: var(--gold-text); }

.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat-grid .chip {
  height: 46px;
  border-radius: 14px;
  justify-content: flex-start;
  padding: 0 12px;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}
.cat-grid .chip.is-on { font-weight: 600; }

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: #0C1220;
  border: 1px solid #232733;
  border-radius: 14px;
}
.segmented button {
  height: 34px;
  min-width: 46px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: background var(--speed), color var(--speed), box-shadow var(--speed);
}
.segmented button.is-on {
  background: linear-gradient(180deg, #F1C976, #DFAB46 70%, #D6A03C);
  color: var(--on-gold);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(228, 176, 74, .26);
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 3px;
  border-radius: var(--r-pill);
  background: #0C1220;
  border: 1px solid #232733;
}
.stepper button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid #2E323B;
  color: var(--gold-text);
  transition: background var(--speed), transform var(--speed);
}
.stepper button:active { transform: scale(.94); background: #23262E; }
.stepper button:disabled { opacity: .35; }
.stepper span { min-width: 30px; text-align: center; font-size: 16px; font-weight: 700; color: var(--text); }

/* ---------- Inputs ---------- */
.field { display: grid; gap: 8px; }
.field-label { font-size: 12px; color: var(--muted); }
.input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 16px;
  outline: none;
  transition: border-color var(--speed), background var(--speed);
}
.input:focus { border-color: var(--gold-border); background: #1B1E25; }
.code-input {
  height: 84px;
  text-align: center;
  direction: ltr;
  font-family: var(--font-code);
  font-size: 38px;
  font-weight: 800;
  letter-spacing: .16em;
  color: var(--gold-code);
  background: #0D131F;
  border-color: #2A2F3E;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.badge-ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.badge-warn, .badge-info { background: var(--info-bg); border-color: #2C4568; color: var(--info); }
.badge-bad { background: var(--bad-bg); border-color: #5A3540; color: var(--bad); }
.badge-review { background: #241F38; border-color: #463A70; color: var(--review); }
.badge-gold { background: #27241C; border-color: var(--gold-border-2); color: var(--gold-text); }

/* ---------- Avatar ---------- */
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  border-radius: 28%;
  background: linear-gradient(160deg, #8B8F99, #5B606B);
  color: #0B0F18;
  font-weight: 700;
  font-size: 17px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 36px; height: 36px; font-size: 14px; border-radius: 10px; }
.avatar-md { width: 46px; height: 46px; font-size: 18px; border-radius: 13px; }
.avatar-lg { width: 56px; height: 56px; font-size: 21px; border-radius: 16px; }
.avatar-xl { width: 92px; height: 92px; font-size: 34px; border-radius: 26px; }
.avatar-ring { box-shadow: 0 0 0 1.5px #5B4F3A, 0 8px 18px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .35); }

/* ---------- Timer ring ---------- */
.timer-ring { position: relative; display: grid; place-items: center; flex: none; }
.timer-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.tr-bg { fill: none; stroke: #2B2F3A; stroke-width: 3.5; }
.tr-fg {
  fill: none;
  stroke: var(--gold);
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke-dashoffset .3s linear, stroke var(--speed);
}
.timer-ring-label { display: grid; justify-items: center; line-height: 1; }
.tr-time { font-size: 26px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.timer-ring-label small { font-size: 11px; color: var(--muted); margin-top: 3px; }
.timer-ring.is-mid .tr-fg { stroke: #EFA54F; }
.timer-ring.is-low .tr-fg { stroke: var(--bad); }
.timer-ring.is-low .tr-time { color: var(--bad); }

/* ---------- Progress segments ---------- */
.seg-track { display: flex; gap: 5px; }
.seg-track i {
  flex: 1;
  max-width: 55px;
  height: 4px;
  border-radius: 2px;
  background: #303133;
  transition: background var(--speed);
}
.seg-track i.is-on { background: var(--gold); }

/* ---------- Status legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); }
.dot-info { background: var(--info); }
.dot-bad { background: var(--bad); }
.dot-review { background: var(--review); }

/* ---------- Switch ---------- */
.switch {
  width: 46px;
  height: 28px;
  border-radius: var(--r-pill);
  background: #23262E;
  border: 1px solid var(--border);
  position: relative;
  flex: none;
  transition: background var(--speed), border-color var(--speed);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #6C7484;
  transition: inset-inline-start var(--speed) var(--ease), background var(--speed);
}
.switch.is-on { background: #2C2413; border-color: var(--gold-border-2); }
.switch.is-on::after { inset-inline-start: 21px; background: var(--gold); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 30;
  max-width: var(--app-max);
  margin: 0 auto;
  height: calc(75px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface-tab);
  border-top: 1px solid #1A1D24;
}
.tabbar button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  transition: color var(--speed);
}
.tabbar button.is-on { color: var(--gold); font-weight: 600; }
.tabbar button svg { width: 22px; height: 22px; }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  inset-inline: 0;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 80;
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 var(--pad);
}
.toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
  padding: 11px 16px;
  border-radius: 14px;
  background: #1B1D24;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .5);
  animation: fadeUp .24s var(--ease) both;
}
.toast-ok { border-color: var(--ok-border); color: var(--ok); background: var(--ok-bg); }
.toast-bad { border-color: #5A3540; color: #FF9AA3; background: var(--bad-bg); }

/* ---------- Sheet / backdrop ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(3, 6, 12, .72);
  backdrop-filter: blur(3px);
  animation: fadeIn .2s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.backdrop > .sheet { animation: sheetUp .28s var(--ease) both; }
@keyframes sheetUp { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet {
  width: 100%;
  max-width: var(--app-max);
  margin: 0 auto;
  padding: 10px var(--pad) calc(22px + env(safe-area-inset-bottom));
  background: #14171F;
  border-top: 1px solid var(--border);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, .55);
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: #33373F;
  margin: 4px auto 14px;
}
.sheet-head b { font-size: 17px; }

/* ---------- Boot ---------- */
.boot-screen {
  min-height: 100dvh;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 10px;
  padding: 24px;
}
.boot-mark { margin-bottom: 10px; animation: popIn .5s var(--ease) both; }
.boot-title { font-size: 30px; font-weight: 700; color: var(--text); }
.boot-sub { font-size: 13px; color: var(--muted); letter-spacing: .04em; }

/* ---------- Misc shared ---------- */
.pts { font-size: 20px; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.pts-zero { color: var(--muted); }
.xp-wrap { display: grid; gap: 6px; }
.xp-bar { height: 8px; border-radius: 4px; background: #23262E; overflow: hidden; }
.xp-bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #BC882E, #F1C976); }
.xp-text { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.divider { height: 1px; background: var(--border-line); }
