:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f3f6f1);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-soft: #e9efe7;
  --text: var(--tg-theme-text-color, #173126);
  --muted: var(--tg-theme-hint-color, #63736a);
  --border: #d4ded2;
  --accent: var(--tg-theme-button-color, #167044);
  --accent-text: var(--tg-theme-button-text-color, #f7fff9);
  --danger: #a43636;
  --danger-bg: #fff0f0;
  --radius: 14px;
  --bar-height: 84px;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, select, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(var(--bar-height) + env(safe-area-inset-bottom) + 18px);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 68px;
  padding: 10px 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.brand-copy { display: grid; min-width: 0; }
.brand-copy strong { font-size: 15px; line-height: 1.3; }
.brand-copy span { color: var(--muted); font-size: 13px; }

.history-button, .text-button {
  margin-left: auto;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 650;
  cursor: pointer;
}

.progress-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.step-caption {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1.12;
  letter-spacing: -0.03em;
}

.step-count {
  flex: 0 0 auto;
  padding-top: 6px;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 4px;
  margin: 18px 0 22px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--border);
}

.progress-track div {
  width: 20%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.form-step { display: grid; gap: 26px; }
.question { display: grid; gap: 10px; }
fieldset.question { min-width: 0; margin: 0; padding: 0; border: 0; }
fieldset.question legend { width: 100%; padding: 0; }

.question-title {
  margin: 0;
  font-size: 16px;
  font-weight: 720;
  line-height: 1.35;
}

.question-hint {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.select-wrap { position: relative; }

select {
  width: 100%;
  min-height: 52px;
  padding: 0 42px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  appearance: none;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.select-wrap::after {
  content: "⌄";
  position: absolute;
  top: 13px;
  right: 16px;
  color: var(--muted);
  pointer-events: none;
}

select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.club-search, .organizer-search { position: relative; }

.club-search input, .organizer-search > input[type="search"] {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  appearance: none;
}

.club-search input::placeholder, .organizer-search input::placeholder { color: var(--muted); opacity: 1; }
.club-search input:focus-visible, .organizer-search input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.club-results, .organizer-results {
  position: absolute;
  z-index: 4;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  max-height: min(280px, 42dvh);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 14px 34px color-mix(in srgb, var(--text) 14%, transparent);
  overscroll-behavior: contain;
}

.club-results button, .organizer-results button {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.club-results button:last-child, .organizer-results button:last-child { border-bottom: 0; }
.club-results button.active, .club-results button:focus-visible,
.organizer-results button.active, .organizer-results button:focus-visible { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); outline: none; }
.club-results button:active, .organizer-results button:active { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }

.organizer-results button { display: grid; gap: 3px; }
.organizer-results button strong { font-size: 14px; }
.organizer-results button span { color: var(--muted); font-size: 12px; }

.club-no-results { padding: 14px; color: var(--muted); font-size: 14px; line-height: 1.4; }

.notes-question textarea {
  width: 100%;
  min-height: 96px;
  padding: 13px 14px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
  outline: none;
}

.notes-question textarea::placeholder { color: var(--muted); opacity: 1; }
.notes-question textarea:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.notes-counter { margin-top: -5px; color: var(--muted); font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }

.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.options.single-column { grid-template-columns: 1fr; }

.option { position: relative; min-width: 0; }
.option input { position: absolute; opacity: 0; pointer-events: none; }

.option label {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease, transform 80ms ease;
}

.option label::before {
  content: "";
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  margin-right: 9px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.option input[type="radio"] + label::before { border-radius: 50%; }

.option input:checked + label {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.option input:checked + label::before {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--surface);
}

.option input[type="checkbox"]:checked + label::before {
  content: "✓";
  display: grid;
  place-items: center;
  box-shadow: none;
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 800;
}

.option input:focus-visible + label { outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent); outline-offset: 2px; }
.option label:active { transform: scale(0.985); }

.form-error {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
}

.draft-status {
  margin: -8px 0 18px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
}

.action-bar {
  position: fixed;
  z-index: 2;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: minmax(74px, 0.72fr) minmax(102px, 1fr) minmax(92px, 1.08fr);
  gap: 10px;
  width: min(100%, 720px);
  min-height: var(--bar-height);
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px);
}

.primary-button, .secondary-button {
  min-height: 52px;
  padding: 0 18px;
  border-radius: var(--radius);
  font-weight: 720;
  white-space: nowrap;
  cursor: pointer;
}

.primary-button { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: 0.62; cursor: wait; }
.full-width { width: 100%; margin-top: 16px; }

.success-state, .error-state {
  min-height: calc(100dvh - 100px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.success-mark {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 40px;
  font-weight: 800;
}

.success-state p, .error-state p { max-width: 34ch; color: var(--muted); line-height: 1.5; }
.success-actions { display: grid; gap: 10px; width: min(100%, 360px); margin-top: 18px; }

.rating-result {
  display: grid;
  gap: 5px;
  width: min(100%, 360px);
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.rating-result span { color: var(--muted); font-size: 12px; }
.rating-result strong { font-size: 18px; }
.rating-result b { color: var(--accent); font-size: 14px; }
.report-card-preview { display: block; width: min(100%, 360px); height: auto; margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); }

.loading-state { padding-top: 34px; }
.skeleton { border-radius: var(--radius); background: var(--surface-soft); }
.skeleton-title { width: 62%; height: 36px; }
.skeleton-line { width: 40%; height: 16px; margin-top: 12px; }
.skeleton-card { width: 100%; height: 120px; margin-top: 24px; }

.reports-heading { display: flex; align-items: center; gap: 14px; margin: 12px 0 22px; }
.reports-heading .text-button { margin: 0; }
.reports-heading h1 { font-size: 25px; margin: 0; }
.report-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 0; border-bottom: 1px solid var(--border); }
.report-row > div { min-width: 0; }
.report-row strong { display: block; font-size: 15px; }
.report-row span { color: var(--muted); font-size: 13px; }
.report-card-button { flex: 0 0 auto; min-height: 40px; padding: 0 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-weight: 650; cursor: pointer; }
.history-section-title { margin: 24px 0 2px; font-size: 16px; }
.history-section-title:first-child { margin-top: 0; }
.draft-row { border-left: 3px solid var(--accent); padding-left: 10px; }
.empty-reports { padding: 26px 0; color: var(--muted); text-align: center; }

[hidden] { display: none !important; }

@media (max-width: 420px) {
  .app-shell { padding-right: 12px; padding-left: 12px; }
  .action-bar { padding-right: 12px; padding-left: 12px; }
  .options { grid-template-columns: 1fr; }
  .brand-copy strong { font-size: 14px; }
  .history-button { font-size: 13px; }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #122019);
    --surface: var(--tg-theme-secondary-bg-color, #1b2d23);
    --surface-soft: #25372d;
    --text: var(--tg-theme-text-color, #edf6f0);
    --muted: var(--tg-theme-hint-color, #a7b9ae);
    --border: #3b5144;
    --accent: var(--tg-theme-button-color, #43a870);
    --accent-text: var(--tg-theme-button-text-color, #0c2115);
    --danger: #ffadad;
    --danger-bg: #3a2323;
  }
}

:root[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #122019);
  --surface: var(--tg-theme-secondary-bg-color, #1b2d23);
  --surface-soft: #25372d;
  --text: var(--tg-theme-text-color, #edf6f0);
  --muted: var(--tg-theme-hint-color, #a7b9ae);
  --border: #3b5144;
  --accent: var(--tg-theme-button-color, #43a870);
  --accent-text: var(--tg-theme-button-text-color, #0c2115);
  --danger: #ffadad;
  --danger-bg: #3a2323;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
