:root {
  --bg: #f6f1e8;
  --bg-alt: #efe4d2;
  --surface: #fffdf8;
  --surface-soft: #f8f1e2;
  --ink: #2f2a24;
  --muted: #6d655d;
  --line: #e7dcc8;
  --gold: #c89b3c;
  --gold-strong: #9e7625;
  --blue: #2f5d8a;
  --red: #b54545;
  --green: #2f6b52;
  --shadow: 0 12px 28px rgba(56, 43, 24, 0.12);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--ink);
  background: radial-gradient(circle at top, var(--bg-alt), var(--bg));
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
}

body {
  padding: 14px;
}

a {
  color: inherit;
}

.container {
  max-width: 980px;
  margin: 0 auto;
}

.top-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.nav-link {
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.nav-link.active {
  background: linear-gradient(135deg, #f5ddb0 0%, #e8c675 100%);
  border-color: #d8b562;
  color: #3b2a06;
}

.hero,
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
}

.hero {
  padding: 24px 20px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #fff9ee 0%, #f3ead8 100%);
}

.badge {
  display: inline-block;
  border-radius: 999px;
  border: 1px solid rgba(200, 155, 60, 0.35);
  background: rgba(200, 155, 60, 0.15);
  color: var(--gold-strong);
  padding: 5px 10px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 8px;
  font-size: 1.9rem;
  line-height: 1.1;
}

.subtitle,
.hint,
.muted {
  color: var(--muted);
  line-height: 1.45;
}

.grid {
  display: grid;
  gap: 14px;
}

.card {
  padding: 16px;
  border-radius: var(--radius);
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.team-name-form {
  display: grid;
  gap: 10px;
}

.team-name-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.team-name-field {
  display: grid;
  gap: 5px;
  font-weight: 700;
}

.team-name-field span {
  font-size: 0.9rem;
  color: #5f574f;
}

.text-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--ink);
  background: #fffdf8;
}

.text-input:focus {
  outline: 2px solid rgba(200, 155, 60, 0.55);
  outline-offset: 1px;
}

.team-name-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.big-link {
  text-decoration: none;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 16px;
  min-height: 120px;
}

.big-link strong {
  display: block;
  font-size: 1.12rem;
  margin-bottom: 6px;
}

.big-link span {
  color: var(--muted);
}

.rule-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fefbf5;
}

.rule-block + .rule-block {
  margin-top: 10px;
}

.rule-block h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.rule-block ul {
  margin: 0;
  padding-left: 20px;
}

.rule-block li {
  margin: 5px 0;
  line-height: 1.4;
}

.highlight {
  color: var(--gold-strong);
  font-weight: 700;
}

.rules-page .container {
  max-width: 1040px;
}

.rules-hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 100% 0%, rgba(200, 155, 60, 0.18), transparent 45%),
    radial-gradient(circle at 0% 100%, rgba(47, 93, 138, 0.12), transparent 38%),
    linear-gradient(125deg, #fffaf0 0%, #f2e4c8 100%);
}

.rules-hero::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(215, 166, 64, 0.35), rgba(215, 166, 64, 0.04));
  pointer-events: none;
}

.rules-pill-row {
  margin-top: 14px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.rules-pill {
  background: rgba(255, 253, 247, 0.85);
  border: 1px solid rgba(231, 220, 200, 0.95);
  border-radius: 12px;
  padding: 10px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rules-pill strong {
  font-size: 0.95rem;
  color: #3b2a06;
}

.rules-pill span {
  font-size: 0.8rem;
  color: #5a534a;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.rules-intro-card {
  margin-bottom: 12px;
  background: linear-gradient(180deg, #fffdf7 0%, #faf1df 100%);
}

.rules-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.rules-grid .rule-block + .rule-block {
  margin-top: 0;
}

.rule-card {
  margin: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #fffefb 0%, #f9f2e4 100%);
}

.rule-card-wide {
  grid-column: 1 / -1;
}

.rule-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.rule-number {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #3b2a06;
  border: 1px solid #d7b46b;
  background: linear-gradient(145deg, #f2d694 0%, #deb05c 100%);
}

.rule-title h3 {
  margin: 0;
}

.live-layout {
  display: grid;
  gap: 14px;
}

.timer-display {
  border-radius: var(--radius);
  background: linear-gradient(135deg, #2f2a24 0%, #41382f 100%);
  color: #fff8e8;
  text-align: center;
  padding: 22px 16px;
}

.period-label {
  margin: 0;
  color: #ead8af;
  font-size: 0.95rem;
}

.time {
  font-size: 4rem;
  line-height: 1;
  margin: 8px 0;
  letter-spacing: 2px;
  font-weight: 800;
}

.phase {
  margin: 0;
  font-size: 1rem;
  color: #fff0cf;
}

.toolbar {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.timer-toolbar {
  grid-template-columns: 1.5fr 1fr;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 11px 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  min-height: 48px;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-primary {
  background: linear-gradient(135deg, #e8c675 0%, #c89b3c 100%);
  color: #2f2413;
}

.btn-secondary {
  background: #eae2d2;
  color: var(--ink);
}

.btn-danger {
  background: #f4d4d4;
  color: #6d2121;
}

.live-toggle-btn {
  min-height: 124px;
  font-size: 2.2rem;
  letter-spacing: 0.02em;
}

.secondary-action-btn {
  min-height: 36px;
  padding: 7px 7px;
  font-size: 0.74rem;
  font-weight: 600;
  opacity: 0.76;
  box-shadow: 0 4px 10px rgba(56, 43, 24, 0.08);
}

.score-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.team {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fffdf8;
}

.team h3 {
  margin-bottom: 6px;
}

.score {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 10px;
  font-weight: 800;
}

.score-controls {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.score-edit-row {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.score-main-btn {
  min-height: 114px;
  font-size: 1.82rem;
}

.score-snitch-btn {
  min-height: 46px;
  font-size: 0.8rem;
  opacity: 0.8;
}

.snitch {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #efd9a6 0%, #ddb771 100%);
  color: #4c3a16;
}

.btn-secondary.secondary-action-btn {
  background: #efe8dc;
  color: #746e67;
}

.btn-danger.secondary-action-btn {
  background: #f3e2e2;
  color: #8d6464;
}

.series-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.series-team {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf4e8;
  padding: 12px;
}

.series-team p {
  margin: 0;
}

.wins {
  font-size: 2rem;
  font-weight: 800;
  margin-top: 6px;
  color: var(--blue);
}

.status-box {
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid #eadab9;
  background: #f9f1df;
  color: #5f4713;
  font-weight: 700;
  padding: 10px;
}

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 10px 0 18px;
}

@page {
  size: A4 portrait;
  margin: 8mm;
}

@media print {
  body.rules-page {
    background: #fff !important;
    padding: 0;
    font-size: 11px;
    line-height: 1.2;
  }

  body.rules-page .container {
    max-width: 100%;
    margin: 0;
  }

  body.rules-page .top-nav,
  body.rules-page .footer-note,
  body.rules-page .rules-intro-card,
  body.rules-page .badge,
  body.rules-page .subtitle {
    display: none !important;
  }

  body.rules-page .hero,
  body.rules-page .card,
  body.rules-page .rule-block,
  body.rules-page .rules-pill {
    box-shadow: none !important;
    background: #fff !important;
  }

  body.rules-page .rules-hero {
    margin-bottom: 6px;
    padding: 8px 10px;
  }

  body.rules-page .rules-hero::after {
    display: none;
  }

  body.rules-page h1 {
    margin: 0 0 6px;
    font-size: 1.4rem;
    line-height: 1.05;
  }

  body.rules-page .rules-pill-row {
    margin-top: 6px;
    gap: 4px;
  }

  body.rules-page .rules-pill {
    border-radius: 8px;
    padding: 4px 5px;
  }

  body.rules-page .rules-pill strong {
    font-size: 0.72rem;
  }

  body.rules-page .rules-pill span {
    font-size: 0.6rem;
    letter-spacing: 0;
  }

  body.rules-page .rules-grid {
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.rules-page .rule-card-wide {
    grid-column: auto;
  }

  body.rules-page .rule-block {
    border-radius: 8px;
    padding: 6px 7px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body.rules-page .rule-title {
    gap: 6px;
    margin-bottom: 4px;
  }

  body.rules-page .rule-number {
    width: 20px;
    height: 20px;
    font-size: 0.72rem;
  }

  body.rules-page .rule-block h3 {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.15;
  }

  body.rules-page .rule-block ul {
    padding-left: 14px;
  }

  body.rules-page .rule-block li {
    margin: 2px 0;
    line-height: 1.2;
    font-size: 0.66rem;
  }
}

@media (max-width: 740px) {
  h1 {
    font-size: 1.55rem;
  }

  .link-grid,
  .team-name-grid,
  .rules-pill-row,
  .rules-grid,
  .score-grid,
  .toolbar,
  .score-controls {
    grid-template-columns: 1fr;
  }

  .rule-card-wide {
    grid-column: auto;
  }

  .time {
    font-size: 3rem;
  }

  .live-toggle-btn {
    min-height: 126px;
  }

  .score-main-btn {
    min-height: 116px;
  }

  .secondary-action-btn {
    min-height: 34px;
    font-size: 0.72rem;
  }

  .timer-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  body.score-page {
    padding: 6px;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.score-page .top-nav,
  body.score-page .hero,
  body.score-page .footer-note {
    display: none;
  }

  body.score-page .container {
    max-width: 100%;
    height: 100%;
  }

  body.score-page .live-layout {
    height: 100%;
    gap: 6px;
    grid-template-rows: auto auto auto;
  }

  body.score-page .card {
    padding: 8px;
    border-radius: 12px;
  }

  body.score-page h2 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    line-height: 1.1;
  }

  body.score-page .timer-display {
    padding: 8px;
    border-radius: 12px;
  }

  body.score-page .period-label {
    font-size: 0.78rem;
  }

  body.score-page .time {
    font-size: 2.15rem;
    margin: 3px 0;
    letter-spacing: 1px;
  }

  body.score-page .phase {
    font-size: 0.8rem;
  }

  body.score-page .toolbar {
    margin-top: 6px;
    gap: 5px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.score-page .timer-toolbar {
    grid-template-columns: 1.45fr 1fr;
  }

  body.score-page button {
    min-height: 44px;
    padding: 8px 6px;
    font-size: 0.78rem;
    line-height: 1.15;
    border-radius: 10px;
  }

  body.score-page .live-toggle-btn {
    min-height: 82px;
    font-size: 1.56rem;
  }

  body.score-page .hint {
    margin: 4px 0 0;
    font-size: 0.73rem;
    line-height: 1.2;
  }

  body.score-page #wakeLockInfo {
    display: none;
  }

  body.score-page .score-grid {
    gap: 6px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.score-page .team {
    padding: 7px;
    border-radius: 10px;
  }

  body.score-page .team h3 {
    margin: 0 0 4px;
    font-size: 0.88rem;
  }

  body.score-page .score {
    font-size: 2rem;
    margin-bottom: 6px;
  }

  body.score-page .score-controls {
    gap: 4px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.score-page .score-main-btn {
    min-height: 66px;
    padding: 6px 4px;
    font-size: 1.04rem;
  }

  body.score-page .score-snitch-btn {
    min-height: 34px;
    font-size: 0.66rem;
  }

  body.score-page .secondary-action-btn {
    min-height: 32px;
    padding: 5px 4px;
    font-size: 0.6rem;
    opacity: 0.7;
  }

  body.score-page .series-board {
    gap: 5px;
    margin-top: 4px;
  }

  body.score-page .series-team {
    padding: 8px;
  }

  body.score-page .wins {
    font-size: 1.4rem;
    margin-top: 2px;
  }

  body.score-page .status-box {
    margin-top: 5px;
    padding: 6px;
    font-size: 0.74rem;
    line-height: 1.2;
  }
}

@media (max-width: 430px) and (max-height: 760px) {
  body.score-page .card {
    padding: 6px;
  }

  body.score-page h2 {
    margin-bottom: 4px;
    font-size: 0.86rem;
  }

  body.score-page .time {
    font-size: 1.9rem;
  }

  body.score-page .score {
    font-size: 1.75rem;
    margin-bottom: 4px;
  }

  body.score-page .score-main-btn {
    min-height: 58px;
    font-size: 0.94rem;
  }

  body.score-page .live-toggle-btn {
    min-height: 66px;
    font-size: 1.24rem;
  }

  body.score-page .secondary-action-btn {
    min-height: 30px;
    font-size: 0.56rem;
    opacity: 0.66;
  }

  body.score-page #liveInfo,
  body.score-page .status-box {
    display: none;
  }
}
