:root {
  color-scheme: light;
  --green: #137b35;
  --green-dark: #0d5926;
  --green-soft: #e7f5eb;
  --red: #a92c35;
  --ink: #17211b;
  --muted: #5d6961;
  --line: #d8e0da;
  --surface: #ffffff;
  --background: #f3f6f4;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--background); }
body { min-height: 100%; margin: 0; color: var(--ink); background: var(--background); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / .96);
  backdrop-filter: blur(10px);
}

.app-brand { display: flex; min-width: 0; align-items: center; gap: 12px; }
.app-brand img { width: 64px; height: 64px; object-fit: contain; flex: 0 0 auto; }
.app-brand div { display: grid; min-width: 0; gap: 2px; }
.app-brand strong { font-size: 1.08rem; line-height: 1.1; }
.app-brand span { overflow: hidden; color: var(--muted); font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }

.connection-status { position: sticky; z-index: 25; top: 76px; padding: 9px 16px; background: #fff1c9; color: #5e4500; text-align: center; }
.connection-status[data-kind="error"] { background: #fbe7e8; color: #7f1f27; }
.connection-status[data-kind="success"] { background: var(--green-soft); color: var(--green-dark); }

.app-main { width: min(100%, 940px); margin: 0 auto; padding: 28px 18px calc(98px + env(safe-area-inset-bottom)); }
.app-view[hidden] { display: none; }
.view-heading { margin-bottom: 24px; }
.view-heading h1 { margin: 4px 0 8px; font-size: clamp(1.75rem, 5vw, 2.45rem); line-height: 1.08; }
.view-heading p:last-child { max-width: 680px; margin: 0; color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0; color: var(--green); font-size: .76rem; font-weight: 800; text-transform: uppercase; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 9px 14px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}
.button:disabled { opacity: .55; cursor: wait; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-dark); }
.button-muted { border-color: #bcc9c0; background: #fff; color: var(--ink); }
.button-danger { border-color: #e2b8bc; background: #fff; color: var(--red); }
.button-icon { width: 44px; padding: 8px; border-color: #bcc9c0; background: #fff; color: var(--ink); font-size: 1.35rem; }

.code-search { margin-bottom: 18px; padding: 18px; border-left: 5px solid var(--green); background: #fff; box-shadow: 0 6px 22px rgb(23 33 27 / .06); }
.code-search label, .app-dialog label { display: block; margin-bottom: 7px; font-size: .86rem; font-weight: 750; }
.input-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }
input, select { width: 100%; min-height: 42px; border: 1px solid #b9c6bd; border-radius: 6px; padding: 9px 11px; background: #fff; color: var(--ink); }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgb(19 123 53 / .25); outline-offset: 2px; }

.filter-bar { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(150px, .7fr) minmax(130px, .55fr) auto; gap: 8px; margin: 22px 0 16px; }
.tournament-list, .watch-list { display: grid; gap: 10px; }
.tournament-card, .watch-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 15px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.tournament-card h2, .watch-card h2 { margin: 0 0 5px; font-size: 1rem; line-height: 1.25; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: .78rem; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 7px; background: #eef2ef; color: #435047; font-size: .72rem; font-weight: 750; }
.badge-running { background: var(--green-soft); color: var(--green-dark); }
.badge-private { background: #fff0cf; color: #705100; }
.card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.card-actions .button { min-height: 36px; padding: 6px 9px; font-size: .78rem; }

.push-panel, .watch-help { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; padding: 17px 18px; border: 1px solid var(--line); background: #fff; }
.push-panel { border-left: 5px solid var(--green); }
.push-panel > div:first-child, .watch-help { min-width: 0; }
.push-panel strong, .push-panel span { display: block; }
.push-panel span, .watch-help p { margin: 4px 0 0; color: var(--muted); font-size: .86rem; line-height: 1.45; }
.push-actions { display: flex; flex-wrap: wrap; gap: 7px; flex: 0 0 auto; }
.watch-help { align-items: flex-end; }
.watch-help > .button { flex: 0 0 auto; }
.assignment { margin-top: 7px; color: var(--green-dark); font-size: .84rem; font-weight: 750; }

.empty-state { padding: 34px 20px; border: 1px dashed #b8c5bc; border-radius: 8px; background: #fff; text-align: center; }
.empty-state strong { display: block; margin-bottom: 5px; }
.empty-state p { margin: 0; color: var(--muted); }

.bottom-nav {
  position: fixed;
  z-index: 40;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 7px max(7px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(7px, env(safe-area-inset-left));
  border-top: 1px solid #cdd7d0;
  background: rgb(255 255 255 / .98);
  box-shadow: 0 -8px 24px rgb(0 0 0 / .08);
  backdrop-filter: blur(10px);
}
.bottom-nav button { display: grid; min-width: 0; min-height: 54px; place-content: center; gap: 3px; border: 0; border-radius: 7px; background: transparent; color: #556159; font-size: .73rem; font-weight: 800; cursor: pointer; }
.bottom-nav button span { color: #7a867e; font-size: .95rem; }
.bottom-nav button.is-active { background: var(--green-soft); color: var(--green-dark); }
.bottom-nav button.is-active span { color: var(--green); }

.app-dialog { width: min(92vw, 520px); max-height: 88vh; overflow: auto; border: 0; border-radius: 8px; padding: 0; box-shadow: 0 24px 70px rgb(0 0 0 / .25); }
.app-dialog::backdrop { background: rgb(8 19 12 / .6); backdrop-filter: blur(3px); }
.app-dialog form { position: relative; display: grid; gap: 12px; padding: 25px; }
.app-dialog h2 { margin: 0; font-size: 1.45rem; }
.app-dialog p { margin: 0; color: var(--muted); line-height: 1.45; }
.dialog-close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border: 0; border-radius: 6px; background: #eef2ef; color: var(--ink); font-size: 1.45rem; cursor: pointer; }
.dialog-note { padding: 10px 12px; background: #f2f6f3; font-size: .84rem; }
.form-error { padding: 9px 11px; background: #fbe7e8; color: #7f1f27 !important; font-size: .84rem; }
#qr-reader { width: 100%; min-height: 260px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; }

.offline-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.offline-page .empty-state { width: min(100%, 520px); }
.offline-page img { width: 130px; height: 130px; object-fit: contain; }
.offline-page h1 { font-size: 1.8rem; }
.offline-page .button { margin-top: 18px; }

@media (max-width: 720px) {
  .app-header { min-height: 68px; }
  .app-brand img { width: 52px; height: 52px; }
  .app-brand strong { font-size: .98rem; }
  .app-brand span { font-size: .72rem; }
  .connection-status { top: 68px; }
  .app-main { padding: 22px 12px calc(94px + env(safe-area-inset-bottom)); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar input { grid-column: 1 / -1; }
  .tournament-card, .watch-card { grid-template-columns: 1fr; align-items: stretch; }
  .card-actions { justify-content: flex-start; }
  .push-panel, .watch-help { align-items: stretch; flex-direction: column; }
  .push-actions { width: 100%; }
  .push-actions .button, .watch-help > .button { flex: 1 1 auto; }
}

@media (max-width: 440px) {
  .app-install { display: none !important; }
  .input-actions { grid-template-columns: minmax(0, 1fr) auto; }
  .input-actions .button-primary { grid-column: 1 / -1; grid-row: 2; }
  .input-actions .button-icon { grid-column: 2; grid-row: 1; }
  .filter-bar { grid-template-columns: 1fr; }
  .filter-bar input { grid-column: auto; }
  .card-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card-actions .button { padding-inline: 5px; }
}
