/* Resultr – resultattavla/sportsida: papper, svart bläck, smala versaler. */

:root {
  --bg: #f2efe8;
  --surface: #fbfaf6;
  --ink: #141414;
  --muted: #6e695f;
  --line: #d9d3c5;
  --home: #1c3fae;
  --away: #c8102e;
  --home-solid: #1c3fae;   /* bakgrund bakom vit text, samma i mörkt läge */
  --away-solid: #c8102e;
  --bar: #141414;
  --bar-ink: #f2efe8;
  --live: #e10600;
  --flash: #ffd23f;
  --danger: #b3261e;
  --radius: 6px;
  --page: 560px;
  --gutter: 16px;
  --display: "Barlow Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.45 var(--body);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-font-smoothing: antialiased;
}

main { max-width: var(--page); margin: 0 auto; padding: 16px var(--gutter); }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.1; font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

[hidden] { display: none !important; }

/* ---------- Knappar & fält ---------- */

button, .button, input { font: inherit; color: inherit; }

button, .button {
  border: 0;
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }

.primary, .danger, .goal, .big {
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.primary { background: var(--ink); color: var(--bg); }
.secondary { background: transparent; border: 1px solid var(--ink); }
.danger { background: var(--danger); color: #fff; }
.big { width: 100%; padding: 15px; font-size: 1.25rem; }
.link {
  background: none; padding: 0; border-radius: 0;
  font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}

/* Textfält – inte kryssrutor/radioknappar, som annars ritas konstigt i t.ex. Safari. */
input:where(:not([type="checkbox"], [type="radio"])) {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
input:where(:not([type="checkbox"], [type="radio"])):focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
input::placeholder { color: var(--muted); opacity: .8; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.error { color: var(--danger); font-weight: 600; margin: 10px 0 0; }

/* ---------- Startsida ---------- */

.start { padding-top: max(36px, env(safe-area-inset-top, 0px)); }
.logo {
  font-size: 2.8rem;
  font-weight: 800;
  font-style: italic;
  letter-spacing: -.01em;
  margin-bottom: 2px;
}
.logo::after { content: ""; display: inline-block; width: .22em; height: .22em; margin-left: .08em; background: var(--live); border-radius: 50%; }
.tagline { color: var(--muted); margin: 0 0 24px; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; margin: -4px 0 20px; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none;
  border-radius: 0;
  padding: 10px 4px 12px;
  margin-bottom: -1px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

.field { display: block; margin-bottom: 16px; }
.field > span, fieldset.field > legend {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.field em { font-style: normal; font-weight: 500; color: var(--muted); text-transform: none; letter-spacing: 0; }
.field small { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; }

fieldset.field { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.sport-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.sport-options.two { grid-template-columns: 1fr 1fr; text-align: center; }
.sport-options.two span { justify-content: center; }
/* Alla knappar i en rad blir lika höga, även om texten bryts i någon av dem. */
.sport-option { display: flex; }
.sport-option input { position: absolute; opacity: 0; pointer-events: none; }
.sport-option span {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}
.sport-option input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 600; }
.sport-option input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

.code-input {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: .4em;
  text-indent: .4em;
  text-align: center;
  text-transform: uppercase;
  padding: 8px;
}
.code-input::placeholder { opacity: .35; }

.teams-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .teams-row { grid-template-columns: 1fr; } }
#formError { margin: 0 0 12px; }

.check { display: flex; gap: 10px; align-items: flex-start; margin: 2px 0 18px; cursor: pointer; font-weight: 600; text-align: left; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; padding: 0; flex: none; accent-color: var(--ink); }
.check > span { flex: 1; min-width: 0; }
.check small { display: block; color: var(--muted); font-weight: 400; font-size: .85rem; }

/* ---------- Matchsida ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(8px + env(safe-area-inset-top, 0px)) var(--gutter) 8px;
  background: var(--bar);
  color: var(--bar-ink);
  border-bottom: 1px solid var(--line);
}
.bar-inner {
  max-width: calc(var(--page) - 2 * var(--gutter));
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.back { color: inherit; text-decoration: none; font-size: 1.9rem; line-height: 1; padding: 0 2px; }
/* Matchkoden ska synas tydligt – grannen på läktaren ska kunna läsa av den. */
.code-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bar-ink);
  color: var(--bar);
  padding: 4px 12px;
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
}
.code-label { font-size: .8rem; letter-spacing: .1em; opacity: .65; }
.code-text { font-size: 1.9rem; line-height: 1; letter-spacing: .16em; margin-right: -.16em; }
.code-qr {
  font-size: .8rem;
  letter-spacing: .06em;
  padding-left: 10px;
  border-left: 1px solid color-mix(in srgb, var(--bar) 30%, transparent);
}
@media (max-width: 420px) { .code-qr { display: none; } }
.conn {
  margin-left: auto;
  font-family: var(--display);
  font-weight: 700;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }
.conn.offline { opacity: .6; }
.conn.offline::before { background: var(--muted); animation: none; }
@keyframes pulse { 50% { opacity: .25; } }

.board { padding: 18px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.sport-label {
  text-align: center;
  color: var(--muted);
  font-family: var(--display);
  font-weight: 600;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  margin-bottom: 6px;
}
.names { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.05;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.name.home { text-align: right; color: var(--home); }
.name.away { text-align: left; color: var(--away); }

.score {
  background: none;
  padding: 0 4px;
  font-family: var(--display);
  font-size: clamp(4rem, 20vw, 5.5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: .9;
  white-space: nowrap;
  border-radius: 4px;
}
.score:disabled { opacity: 1; }
.score .dash { margin: 0 .06em; color: var(--muted); font-weight: 600; }
.score.bump { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 30% { background: var(--flash); color: #141414; } }

.clock-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.clock {
  background: none;
  border: 1px dashed var(--line);
  padding: 4px 12px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.clock.set { border: 1px solid var(--ink); color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.clock:disabled { opacity: 1; }
.clock.period { border-style: solid; border-color: var(--ink); color: var(--ink); }

.ended { text-align: center; margin-top: 14px; }
.ended p {
  display: inline-block;
  margin: 0 0 6px;
  padding: 2px 10px;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.ended .link { display: block; margin: 0 auto; font-size: .9rem; }

.goals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.goal { padding: 22px 8px; font-size: 1.7rem; color: #fff; }
.goal.home { background: var(--home-solid); }
.goal.away { background: var(--away-solid); }
.goal:active { transform: translateY(1px); filter: brightness(.92); }

.board-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.undo { padding: 8px 0; background: none; color: var(--muted); font-size: .9rem; text-align: left; }
.end-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--ink);
  padding: 6px 12px;
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.chip {
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 7px 12px;
  font-size: .92rem;
  font-weight: 500;
  white-space: nowrap;
}
.chip:active { border-color: var(--ink); }

.comment-form { display: flex; gap: 8px; margin-bottom: 18px; }

/* ---------- Layout på matchsidan ----------
   Mobil: en kolumn – tavla, kommentarer, flöde, sist inställningar.
   Stor skärm: tavla och knappar till vänster (står kvar), flödet till höger. */

.match-layout { display: flex; flex-direction: column; }
.panel { display: contents; }
.feed-col { order: 1; }
.footer { order: 2; }
.feed-heading { display: none; }

@media (min-width: 900px) {
  :root { --page: 1120px; --gutter: 32px; }
  html { font-size: 106.25%; }
  .match { padding-top: 28px; }
  .match-layout {
    display: grid;
    grid-template-columns: minmax(0, 500px) minmax(0, 1fr);
    gap: 64px;
    align-items: start;
  }
  .panel { display: block; }
  .board { padding-top: 8px; }
  .quick { flex-wrap: wrap; overflow: visible; }
  .feed-heading {
    display: block;
    font-size: .95rem;
    color: var(--muted);
    letter-spacing: .12em;
    margin: 6px 0 10px;
  }
  .start { max-width: 560px; padding-top: 12vh; }
  .logo { font-size: 3.4rem; }
}

@media (min-width: 900px) and (min-height: 760px) {
  .panel { position: sticky; top: 84px; }
}

@media (min-width: 1500px) {
  html { font-size: 112.5%; }
}

/* ---------- Liveflöde ---------- */

.feed { list-style: none; margin: 0 0 24px; padding: 0; border-top: 2px solid var(--ink); }
.ev {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.ev-time {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.ev-time.clock-time { font-weight: 500; font-size: .95rem; color: var(--muted); }
.ev-body { min-width: 0; overflow-wrap: anywhere; }
.ev-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.tag {
  font-family: var(--display);
  font-weight: 700;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 1px 6px;
  border: 1px solid var(--ink);
  border-radius: 3px;
}
.ev-goal .tag { color: #fff; border-color: transparent; }
.ev-goal.team-home .tag { background: var(--home-solid); }
.ev-goal.team-away .tag { background: var(--away-solid); }
.ev-end .tag { background: var(--ink); color: var(--bg); }
.ev-goal .ev-text { font-weight: 700; }
.ev-score { font-family: var(--display); font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.ev-comment .ev-text { font-size: 1.02rem; }
.ev-sub { font-weight: 600; margin-top: 2px; }
.ev-meta { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.ev-actions { display: flex; }
.ev-actions button { background: none; padding: 2px 8px; color: var(--muted); }
.empty { padding: 28px 8px; color: var(--muted); text-align: center; }

.footer { color: var(--muted); font-size: .92rem; padding-top: 4px; }
.footer .link { color: var(--ink); }

/* Bara titta: inga knappar för att rapportera. */
.watching .goals,
.watching .board-actions,
.watching .quick,
.watching .comment-form,
.watching .admin,
.watching .ended .link,
.watching .ev-actions { display: none; }
.admin { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.admin h3 { color: var(--ink); }
.admin-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-buttons button { padding: 8px 12px; font-size: .92rem; }

/* ---------- Statistik ---------- */

.stats { max-width: 760px; padding-top: max(28px, env(safe-area-inset-top, 0px)); }
.back-link { display: inline-block; color: var(--muted); text-decoration: none; font-weight: 600; margin-bottom: 14px; }
.stats-title { font-size: 2.6rem; font-weight: 800; font-style: italic; margin-bottom: 2px; }
.stats .tagline { margin-bottom: 20px; }

.stats-live {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 16px;
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
.stats-live::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }

/* Tre stora siffror mellan två linjer – som en resultattavla. */
.headline {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  margin-bottom: 28px;
}
.headline-item { padding: 14px 4px 12px; text-align: center; }
.headline-item + .headline-item { border-left: 1px solid var(--line); }
.headline-value {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  line-height: .95;
  font-variant-numeric: tabular-nums;
}
.headline-label {
  margin-top: 6px;
  font-family: var(--display); font-weight: 700; font-size: .85rem;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}

.stats-section { margin-bottom: 28px; }
.stats-section h2 {
  font-size: .95rem; letter-spacing: .1em; color: var(--muted);
  padding-bottom: 8px; margin-bottom: 0; border-bottom: 2px solid var(--ink);
}

.facts { width: 100%; border-collapse: collapse; }
.facts th, .facts td { padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts th { text-align: left; font-weight: 500; }
.facts th small { color: var(--muted); font-size: .82rem; margin-left: 4px; }
.facts td {
  text-align: right; font-family: var(--display); font-weight: 700; font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li {
  display: grid;
  grid-template-columns: 6.5rem 1fr 2rem;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 8px; }
.bar-fill { display: block; height: 100%; min-width: 4px; background: var(--ink); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-family: var(--display); font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.bar-list .empty-row { display: block; color: var(--muted); padding: 12px 0; }

@media (min-width: 900px) {
  .stats-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
}

.updated { color: var(--muted); font-size: .85rem; text-align: center; }


/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--ink);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  z-index: 20;
}
.toast .link { color: var(--flash); }

/* ---------- Dialog ---------- */

dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(10, 10, 10, .55); }
dialog p { color: var(--muted); margin: 0 0 14px; }
dialog label { display: block; font-weight: 600; margin-bottom: 12px; }
dialog label input { margin-top: 4px; font-weight: 400; }
.dlg-buttons { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 18px; }
.dlg-buttons button { flex: 1; }

.share { text-align: center; }
.share-code { font-family: var(--display); font-size: 3rem; font-weight: 800; letter-spacing: .25em; text-indent: .25em; line-height: 1; margin: 4px 0 8px; }
.qr { width: 210px; max-width: 100%; aspect-ratio: 1; background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 6px; margin: 4px auto 8px; display: block; }
.share-url { font-size: .88rem; user-select: all; overflow-wrap: anywhere; }
.share-btn { width: 100%; }
