:root {
  --color-ink-950: #171513;
  --color-ink-700: #453d35;
  --color-ink-500: #6d604e;
  --color-paper-50: #fffdf5;
  --color-paper-100: #fff8e5;
  --color-paper-200: #f7ebcb;
  --color-paper-300: #efd99e;
  --color-red-500: #e93838;
  --color-blue-500: #2f71ff;
  --color-green-500: #24b866;
  --color-orange-500: #ff8b1f;
  --color-pink-500: #ff4f9b;
  --color-teal-500: #00a88a;
  --color-yellow-200: #fff0a8;
  --color-success-100: #c9ffd9;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 14px;
  --space-5: 18px;
  --space-6: 24px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --stroke-md: 3px;
  --stroke-sm: 2px;
  --font-family-display: "Trebuchet MS", "Avenir Next", Verdana, sans-serif;
  --font-size-xs: 0.68rem;
  --font-size-sm: 0.76rem;
  --font-size-md: 0.92rem;
  --font-size-lg: 1.28rem;
  --font-weight-bold: 900;
  --font-weight-black: 1000;
  --shadow-hard: 5px 5px 0 var(--color-ink-950);
  --shadow-control: 3px 3px 0 var(--color-ink-950);
  --shadow-soft: 0 18px 40px rgba(23, 21, 19, 0.16);
  --surface-page: var(--color-paper-200);
  --surface-panel: var(--color-paper-100);
  --surface-input: var(--color-paper-50);
  --surface-notice: var(--color-yellow-200);
  --text-primary: var(--color-ink-950);
  --text-muted: var(--color-ink-500);
  --border-strong: var(--color-ink-950);
  --accent-primary: var(--color-pink-500);
  --accent-secondary: var(--color-teal-500);
  --accent-danger: var(--color-red-500);
  --button-radius: var(--radius-md);
  --card-radius: var(--radius-md);
  --control-height: 44px;
  --ink: var(--text-primary);
  --paper: var(--surface-page);
  --paper-deep: var(--color-paper-300);
  --card: var(--surface-panel);
  --line: var(--border-strong);
  --muted: var(--text-muted);
  --red: var(--color-red-500);
  --blue: var(--color-blue-500);
  --green: var(--color-green-500);
  --orange: var(--color-orange-500);
  --pink: var(--color-pink-500);
  --teal: var(--color-teal-500);
  --shadow: var(--shadow-hard);
  --soft-shadow: var(--shadow-soft);
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-family-display);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 12px 12px, rgba(23, 21, 19, 0.1) 2px, transparent 2px) 0 0 / 28px 28px,
    linear-gradient(135deg, #fbf0d2 0%, #f6dfaa 100%);
}

body {
  min-height: 100vh;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  min-height: 100vh;
  padding: 12px 12px calc(88px + env(safe-area-inset-bottom));
}

.shell {
  width: min(100%, 520px);
  margin: 0 auto;
}

.topbar {
  z-index: 20;
  padding: env(safe-area-inset-top) 0 10px;
}

.brand-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(115deg, rgba(255, 79, 155, 0.16), transparent 35%),
    linear-gradient(290deg, rgba(0, 168, 138, 0.18), transparent 45%),
    var(--card);
  box-shadow: var(--shadow);
}

.brand-card:after {
  content: "";
  position: absolute;
  right: -28px;
  bottom: -36px;
  width: 150px;
  height: 92px;
  transform: rotate(-12deg);
  border: 3px solid rgba(23, 21, 19, 0.18);
  border-radius: 999px;
  background: repeating-linear-gradient(90deg, rgba(23, 21, 19, 0.08) 0 8px, transparent 8px 16px);
}

.brand-copy {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--pink);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 3px;
  font-size: clamp(1.55rem, 9vw, 2.3rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.28rem;
  line-height: 1;
  text-transform: uppercase;
}

h3 {
  margin-bottom: 4px;
  font-size: 1rem;
  line-height: 1.1;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.sync-line {
  display: inline-flex;
  margin: 8px 0 0;
  padding: 4px 7px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fffdf5;
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sync-line.shared {
  background: #c9ffd9;
}

.sync-line.local {
  background: #fff0a8;
}

.mode-pill {
  position: relative;
  z-index: 1;
  min-width: 82px;
  padding: 8px 10px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.76rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.panel {
  margin-top: 14px;
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--soft-shadow);
}

.panel.is-loud {
  background:
    linear-gradient(135deg, rgba(255, 139, 31, 0.18), transparent 42%),
    linear-gradient(270deg, rgba(47, 113, 255, 0.13), transparent 54%),
    var(--card);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.stack {
  display: grid;
  gap: 10px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
}

.field span,
.field label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.input,
.select {
  width: 100%;
  min-height: var(--control-height);
  padding: 10px 11px;
  border: var(--stroke-md) solid var(--line);
  border-radius: var(--button-radius);
  background: var(--surface-input);
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(23, 21, 19, 0.18);
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--line) 50%), linear-gradient(135deg, var(--line) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 12px) 18px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.btn {
  display: inline-flex;
  min-height: var(--control-height);
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 13px;
  border: var(--stroke-md) solid var(--line);
  border-radius: var(--button-radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--line);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--line);
}

.btn.primary {
  background: var(--accent-primary);
  color: white;
}

.btn.dark {
  background: var(--ink);
  color: var(--paper);
}

.btn.ghost {
  background: transparent;
  box-shadow: none;
}

.btn.full {
  width: 100%;
}

.btn.small {
  min-height: 36px;
  padding: 8px 10px;
  font-size: 0.78rem;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.tabs {
  position: fixed;
  right: auto;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  width: min(calc(100vw - 20px), 520px);
  margin: 0 auto;
  padding: 8px;
  transform: translateX(-50%);
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 248, 229, 0.94);
  box-shadow: 0 10px 0 rgba(23, 21, 19, 0.2);
  backdrop-filter: blur(16px);
}

.tab {
  min-height: 48px;
  padding: 7px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.tab.active {
  background: var(--ink);
  color: var(--paper);
}

.tab b {
  display: block;
  margin-bottom: 2px;
  font-size: 1rem;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}

.avatar-choice {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 3px 3px 0 rgba(23, 21, 19, 0.16);
}

.avatar-choice.active {
  outline: 4px solid var(--pink);
  outline-offset: 2px;
}

.avatar {
  --avatar-color: var(--pink);
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  flex: 0 0 auto;
  transform: rotate(-4deg);
  border: 3px solid var(--line);
  border-radius: 12px 18px 10px 20px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.34), transparent 45%),
    var(--avatar-color);
  color: #fffdf5;
  box-shadow: 3px 3px 0 var(--line);
  font-size: 1.1rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.avatar.shape-2 {
  transform: rotate(5deg);
  border-radius: 999px 999px 14px 999px;
}

.avatar.shape-3 {
  transform: rotate(-8deg);
  border-radius: 8px 24px 8px 24px;
}

.avatar.shape-4 {
  transform: rotate(7deg);
  border-radius: 22px 8px 22px 8px;
}

.avatar.image-avatar {
  overflow: visible;
  transform: rotate(-3deg);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.avatar.image-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(2px 2px 0 rgba(23, 21, 19, 0.42));
}

.avatar-choice .avatar.image-avatar {
  width: 82%;
  height: 82%;
}

.team-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--team-color);
  color: white;
  box-shadow: var(--shadow);
}

.team-card:before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.25), transparent 35%),
    repeating-linear-gradient(-20deg, rgba(255, 255, 255, 0.09) 0 8px, transparent 8px 18px);
  pointer-events: none;
}

.team-card > * {
  position: relative;
  z-index: 1;
}

.team-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.team-title h3 {
  margin: 0;
  font-size: 1.05rem;
  text-transform: uppercase;
}

.score {
  font-size: 2.25rem;
  font-weight: 1000;
  line-height: 0.9;
}

.score-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mini-stat {
  padding: 7px;
  border: 2px solid rgba(23, 21, 19, 0.6);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.22);
  color: white;
}

.mini-stat span {
  display: block;
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.mini-stat b {
  font-size: 1.1rem;
}

.cap-track {
  height: 14px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.36);
}

.cap-fill {
  height: 100%;
  width: var(--cap-width);
  background: var(--ink);
}

.list {
  display: grid;
  gap: 9px;
}

.round-ledger {
  display: grid;
  gap: 12px;
}

.round-card {
  display: grid;
  gap: 10px;
}

.player-row,
.event-row,
.shop-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fffdf5;
  box-shadow: 3px 3px 0 rgba(23, 21, 19, 0.14);
}

.player-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.event-row.highlight {
  background:
    linear-gradient(90deg, rgba(255, 79, 155, 0.13), transparent 58%),
    #fffdf5;
}

.event-row.is-reset {
  border-style: dashed;
  opacity: 0.68;
}

.player-meta p,
.event-row p,
.shop-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.score-detail {
  padding-left: 8px;
  border-left: 3px solid rgba(23, 21, 19, 0.18);
}

.score-detail.muted {
  color: rgba(109, 96, 78, 0.72);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 4px 8px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.dark {
  background: var(--ink);
  color: var(--paper);
}

.badge.color {
  background: var(--badge-color);
  color: white;
}

.shop-card {
  position: relative;
  overflow: hidden;
}

.shop-card-button {
  width: 100%;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.shop-card-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(23, 21, 19, 0.36);
}

.shop-card:after {
  content: "";
  position: absolute;
  top: 12px;
  right: -18px;
  width: 84px;
  height: 48px;
  transform: rotate(13deg);
  border: 3px solid rgba(23, 21, 19, 0.16);
  border-radius: 999px;
  background: rgba(255, 79, 155, 0.12);
}

.sticker-icon {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 14px 22px 10px 18px;
  background: var(--sticker-color);
  color: white;
  box-shadow: 3px 3px 0 var(--line);
  font-size: 0.78rem;
  font-weight: 1000;
  text-align: center;
  text-transform: uppercase;
}

.sticker-icon.large {
  width: 72px;
  height: 72px;
  font-size: 0.92rem;
}

img.sticker-icon {
  object-fit: contain;
  padding: 0;
}

.shop-head {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.price {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  transform: rotate(8deg);
  border: 3px solid var(--line);
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-weight: 1000;
}

.shop-detail {
  display: grid;
  gap: 12px;
}

.shop-hero,
.shop-detail-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.shop-hero {
  grid-template-columns: 1fr;
  padding: 12px;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: var(--card-radius);
  background:
    linear-gradient(130deg, color-mix(in srgb, var(--shop-color) 30%, transparent), transparent 58%),
    var(--surface-input);
  box-shadow: 4px 4px 0 rgba(23, 21, 19, 0.2);
}

.shop-hero-copy {
  display: grid;
  gap: 8px;
}

.shop-hero-copy h2 {
  margin: 0;
}

.shop-visual {
  display: block;
  width: 100%;
  max-height: 230px;
  object-fit: contain;
  border: 3px solid var(--line);
  border-radius: var(--card-radius);
  background: #fffdf5;
  box-shadow: 4px 4px 0 var(--line);
}

.shop-visual.fallback {
  display: grid;
  min-height: 190px;
  place-items: center;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.34), transparent 45%),
    var(--sticker-color);
  color: white;
  font-size: 1.6rem;
  font-weight: 1000;
  text-align: center;
  text-transform: uppercase;
}

.explain-card {
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: var(--card-radius);
  background: var(--surface-input);
  box-shadow: 3px 3px 0 rgba(23, 21, 19, 0.14);
}

.explain-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.rule-steps {
  display: grid;
  gap: 8px;
}

.rule-step {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 2px solid rgba(23, 21, 19, 0.36);
  border-radius: var(--card-radius);
  background: #fffdf5;
}

.rule-step span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 1000;
}

.rule-step p {
  margin: 0;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
}

.buy-state {
  padding: 9px 10px;
  border: 2px dashed rgba(23, 21, 19, 0.46);
  border-radius: var(--card-radius);
  background: var(--surface-notice);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.buy-state.ready {
  border-style: solid;
  background: var(--color-success-100);
}

.empty {
  padding: 18px;
  border: 3px dashed rgba(23, 21, 19, 0.45);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.notice {
  padding: 10px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--surface-notice);
  box-shadow: 3px 3px 0 rgba(23, 21, 19, 0.16);
  font-weight: 800;
}

.notice.compact {
  font-size: 0.84rem;
  line-height: 1.3;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.switch input {
  width: 22px;
  height: 22px;
  accent-color: var(--pink);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.danger {
  color: #b01818;
}

.tiny {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

@media (min-width: 760px) {
  .app {
    padding-top: 24px;
  }

  .shell {
    width: min(100%, 760px);
  }

  .dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: start;
  }

  .shop-hero {
    grid-template-columns: minmax(0, 1fr) 260px;
  }
}
