:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #dedcd6;
  --text: #1c1b19;
  --muted: #6c6a64;
  --accent: #2f6f4f;
  --accent-soft: #e4efe8;
  --negative: #a33a2a;
  --positive: #2f6f4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2123;
    --surface-2: #272a2d;
    --border: #35393d;
    --text: #e9e8e4;
    --muted: #9b9a94;
    --accent: #6cc295;
    --accent-soft: #23342b;
    --negative: #e8836f;
    --positive: #6cc295;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; }
h1 { font-size: 1.25rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }

a { color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #10231a; } }
button.primary:hover { filter: brightness(1.07); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 0.25rem 0.4rem; }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.danger:hover { border-color: var(--negative); color: var(--negative); }
button[disabled] { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.2rem; }

.app { max-width: 1060px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

header.top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
header.top .brand { display: flex; align-items: baseline; gap: 0.6rem; }
header.top .tagline { color: var(--muted); font-size: 0.8rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card > header { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }

.grid { display: grid; gap: 0.75rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.row { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.row > .shrink { flex: 0 0 auto; }
/* A .row marked .shrink is a toolbar: its children size to their content rather
   than stretching, and a long <select> gives way before the buttons do. */
.row.shrink > * { flex: 0 0 auto; }
/* The header toolbar wraps rather than pushing buttons off a narrow screen. */
/* Verktygsraden tar det utrymme som blir över efter rubriken, så knapparna
   håller ihop på en rad så länge de får plats. */
header.top .toolbar { flex: 1 1 auto; justify-content: flex-end; max-width: 100%; }
.row.shrink > select { flex: 0 1 auto; min-width: 0; text-overflow: ellipsis; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Tabeller får rulla i sidled inuti sitt kort i stället för att dra hela sidan. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; padding: 0 0.25rem; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
td.actions { text-align: right; white-space: nowrap; }

.pill {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
/* Rader som bara finns på telefon, där kolumner har fällts ihop. */
.only-sm { display: none; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.pos { color: var(--positive); }
.neg { color: var(--negative); }
.mono { font-variant-numeric: tabular-nums; }

.stat-row { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.8rem; }
.stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat .v { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 0.15rem; }

.transfer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-soft);
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.transfer .who { flex: 1 1 200px; }
.transfer .amount { font-weight: 600; font-variant-numeric: tabular-nums; }

.participants { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.participants .p-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.participants .p-row:last-child { border-bottom: none; }
.participants .p-row input[type="checkbox"] { width: auto; flex: 0 0 auto; margin: 0; }
.participants .p-row .p-name { flex: 1 1 auto; }
.participants .p-row .p-value { flex: 0 0 110px; }
.participants .p-row .p-unit { flex: 0 0 auto; color: var(--muted); font-size: 0.8rem; min-width: 2.4rem; }

.empty { color: var(--muted); text-align: center; padding: 1.5rem 0.5rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  max-width: min(90vw, 480px);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.toast.error { background: var(--negative); color: #fff; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1rem;
  max-width: min(94vw, 420px);
  width: 100%;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

@media (max-width: 560px) {
  .app { padding: 1rem 0.75rem 3rem; }
  th, td { padding: 0.45rem 0.25rem; }
  table { font-size: 0.86rem; }
  th { font-size: 0.68rem; }
  .hide-sm { display: none; }
  .only-sm { display: block; margin-top: 0.1rem; }
  th .only-sm { display: inline; margin: 0; }

  /* Fem flikar ska rymmas utan att någon hamnar utanför kanten. */
  .tabs { gap: 0; }
  .tabs button { padding: 0.5rem 0.35rem; font-size: 0.8rem; }

  /* Två fält i bredd i formulären, annars blir de orimligt höga på telefon. */
  .grid.two { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 0.6rem; }

  /* Tre nyckeltal i bredd i stället för två, så raden inte blir en kolumn. */
  .stat-row { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 0.4rem; }
  .stat { padding: 0.5rem 0.4rem; }
  .stat .v { font-size: 1.02rem; }

  /* Årskortets rubrik: år och resmål på en egen rad, knapparna under.
     Annars bryts resmålet ned under årtalet och raden ser trasig ut. */
  .season > header { flex-wrap: wrap; }
  .season > header > div:first-child { flex: 1 1 100%; }
  .season .label { margin-left: 0.4rem; }

  /* Avräkningsraden: namn och belopp på en rad, knappen under i full bredd.
     Annars hamnar knappen ibland bredvid och ibland under, beroende på beloppets längd. */
  .transfer { display: grid; grid-template-columns: 1fr auto; gap: 0.45rem 0.5rem; }
  .transfer .who { grid-column: 1; }
  .transfer .amount { grid-column: 2; text-align: right; }
  .transfer button { grid-column: 1 / -1; }

  /* Radknapparna visas som symboler; texten finns kvar för skärmläsare. */
  td.actions .label { display: none; }
  td.actions button { padding: 0.3rem 0.4rem; font-size: 1rem; }
}

/* Symbolen syns bara när texten är dold. */
td.actions .icon { display: none; }
@media (max-width: 560px) {
  td.actions .icon { display: inline; }
}

/* ------------------------------------------------------------ course log */

.navlink {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.navlink:hover { background: var(--surface-2); }

.season { padding-bottom: 0.5rem; }
.season > header { align-items: baseline; }
.season .year { font-variant-numeric: tabular-nums; font-size: 1.1rem; font-weight: 600; }
.season .label { color: var(--muted); margin-left: 0.5rem; font-size: 0.9rem; }
.season.blank { background: var(--surface-2); }

.course-list { list-style: none; margin: 0; padding: 0; }
.course-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}
.course-list li:last-child { border-bottom: none; }
/* The name reads as text until you touch it, then behaves as the field it is. */
.course-list .c-name {
  flex: 1 1 auto;
  border-color: transparent;
  background: transparent;
  padding: 0.25rem 0.35rem;
}
.course-list li:hover .c-name { border-color: var(--border); background: var(--surface); }
.course-list .c-name:focus { border-color: var(--accent); background: var(--surface); }
.course-list .c-times { flex: 0 0 auto; }
.course-list .c-tools { flex: 0 0 auto; display: flex; gap: 0.1rem; opacity: 0.55; }
.course-list li:hover .c-tools, .course-list li:focus-within .c-tools { opacity: 1; }

.add-course { display: flex; gap: 0.4rem; margin-top: 0.6rem; }
.add-course input[type="text"] { flex: 1 1 auto; }
.add-course input[type="number"] { flex: 0 0 72px; }
.add-course button { flex: 0 0 auto; }

.hero {
  margin: 0 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.hero img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 340px;
  object-fit: cover;
  object-position: center 62%;
}
.hero figcaption {
  padding: 0.55rem 0.8rem;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ----------------------------------------------------------------- the game */

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.hud-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  text-align: center;
}
.hud-item .k { display: block; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.hud-item .v { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }

.stage {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  background: #4f8f4a;
}
.stage canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;          /* dragging steers the player, never scrolls the page */
  -webkit-user-select: none;
  user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(10, 20, 12, 0.62);
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.overlay-box {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  max-height: 100%;
  overflow-y: auto;
}
.overlay-box h2 { margin-bottom: 0.3rem; }
.overlay-box p { margin: 0.3rem 0; }
.overlay-box .big {
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 0.3rem 0;
}
.overlay-box .keys { font-size: 0.8rem; color: var(--muted); }
.overlay-box button { margin-top: 0.6rem; }
.overlay-box .save-row { display: flex; gap: 0.4rem; margin-top: 0.7rem; }
.overlay-box .save-row input { flex: 1 1 auto; }
.overlay-box .save-row button { flex: 0 0 auto; margin-top: 0; }

.price-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(66px, 1fr));
  gap: 0.2rem;
  margin: 0.5rem 0;
  font-size: 0.72rem;
}
.price-list span {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 0.2rem 0.3rem;
  font-variant-numeric: tabular-nums;
}
