:root {
  --ink: #1c2a24;
  --ink-soft: #3d5248;
  --paper: #f3f7f2;
  --paper-2: #e4efe6;
  --sea: #1f6f5b;
  --sea-deep: #145244;
  --sun: #e8a317;
  --sun-soft: #f6d48a;
  --mark-row: rgba(31, 111, 91, 0.14);
  --mark-col: rgba(232, 163, 23, 0.18);
  --focus-ring: #145244;
  --danger-soft: #6b3a2a;
  --ok: #1f6f5b;
  --radius: 14px;
  --touch: 44px;
  --font-display: "Fraunces", "Palatino Linotype", Palatino, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --shadow: 0 10px 30px rgba(28, 42, 36, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #d9eee4 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #ffe9b8 0%, transparent 45%),
    linear-gradient(180deg, #f7fbf6 0%, var(--paper) 40%, #eef5ef 100%);
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cpath fill='none' stroke='%231f6f5b' stroke-opacity='0.07' d='M0 60h120M60 0v120'/%3E%3C/svg%3E");
}

.app {
  position: relative;
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.brand {
  display: grid;
  gap: 0.15rem;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
  color: var(--sea-deep);
  line-height: 1.1;
}

.brand-sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 1rem;
}

.mode-hint,
.action-cue {
  margin: 0 0 0.65rem;
  color: var(--ink-soft);
  font-size: 0.98rem;
  font-weight: 650;
}

.action-cue {
  color: var(--sea-deep);
}

.mode-toggle {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.3rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(28, 42, 36, 0.1);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.mode-toggle button {
  min-height: var(--touch);
  min-width: 6.5rem;
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.mode-toggle button[aria-pressed="true"] {
  background: var(--sea);
  color: #fff;
  box-shadow: var(--shadow);
}

.layout {
  display: grid;
  gap: 1rem;
}

/* Mobil først: gangestykke (og bud) over tabellen, så første skærm forklarer stykket. */
.piece {
  order: 1;
}

.table-shell {
  order: 2;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.9fr);
    align-items: start;
  }

  .table-shell {
    order: 1;
  }

  .piece {
    order: 2;
  }
}

.panel {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(28, 42, 36, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.table-shell {
  max-width: 100%;
  position: relative;
}

.table-scroll {
  position: relative;
  overflow: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  /* Begræns højde på mobil, så stykke + udsnit af gitter deler første viewport */
  max-height: min(52vh, 420px);
}

@media (min-width: 900px) {
  .table-scroll {
    max-height: none;
  }
}

.scroll-fade {
  display: none;
  margin: 0.55rem 0 0;
  color: var(--sea-deep);
  font-size: 0.9rem;
  font-weight: 700;
}

.table-shell.has-more-x .table-scroll {
  mask-image: linear-gradient(90deg, #000 86%, transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, #000 86%, transparent 100%);
}

.table-shell.has-more-x .scroll-fade {
  display: block;
}

.scroll-fade::before {
  content: "Træk sidelæns for flere tal →";
}

.mode-practice #jump-panel {
  display: none;
}

.mode-explore #practice-policy {
  display: none;
}

.times-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.times-table th,
.times-table td {
  min-width: var(--touch);
  min-height: var(--touch);
  height: var(--touch);
  box-sizing: border-box;
  text-align: center;
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid rgba(28, 42, 36, 0.06);
  border-right: 1px solid rgba(28, 42, 36, 0.04);
  font-size: 0.95rem;
}

.times-table th {
  background: rgba(228, 239, 230, 0.85);
  color: var(--sea-deep);
  font-weight: 700;
  position: sticky;
  z-index: 1;
}

.times-table thead th {
  top: 0;
}

.times-table tbody th {
  left: 0;
}

.times-table .corner {
  left: 0;
  z-index: 2;
}

.times-table td {
  background: rgba(255, 255, 255, 0.55);
  cursor: pointer;
}

.times-table td.row-mark,
.times-table th.row-mark {
  background: var(--mark-row);
  box-shadow: inset 3px 0 0 var(--sea);
}

.times-table td.col-mark,
.times-table th.col-mark {
  background: var(--mark-col);
  box-shadow: inset 0 3px 0 var(--sun);
}

.times-table td.row-mark.col-mark {
  background: color-mix(in srgb, var(--mark-row) 55%, var(--mark-col));
}

.times-table td.focus-cell {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
  font-weight: 700;
  background: #fff;
  z-index: 1;
  position: relative;
}

.times-table td:focus-visible,
.times-table td.focus-cell:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
}

.piece {
  display: grid;
  gap: 0.75rem;
}

.piece-label {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.piece-main {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.piece-main #product {
  color: var(--sea-deep);
}

.jump-note {
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: rgba(246, 212, 138, 0.45);
  color: var(--ink);
  font-weight: 600;
}

.controls {
  display: grid;
  gap: 0.65rem;
}

.controls h2 {
  margin: 0;
  font-size: 1rem;
  font-family: var(--font-display);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.45rem;
  align-items: end;
}

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--ink-soft);
}

input[type="text"],
input[type="number"] {
  min-height: var(--touch);
  width: 100%;
  border: 1.5px solid rgba(28, 42, 36, 0.18);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 1.05rem;
  background: #fff;
  color: var(--ink);
}

input:focus-visible,
button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--sea) 70%, white);
  outline-offset: 2px;
}

.times-sep {
  padding-bottom: 0.7rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  border: 0;
  border-radius: 12px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--sea);
  color: #fff;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--paper-2);
  color: var(--sea-deep);
  border: 1px solid rgba(28, 42, 36, 0.1);
}

.btn-ghost {
  background: transparent;
  color: var(--sea-deep);
  border: 1px dashed rgba(31, 111, 91, 0.35);
}

.practice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.practice-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.status {
  min-height: 1.4em;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  background: rgba(228, 239, 230, 0.7);
  color: var(--ink);
  font-weight: 600;
}

.status:empty {
  display: none;
}

.help {
  margin: 1rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.help kbd {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  border: 1px solid rgba(28, 42, 36, 0.15);
  background: #fff;
  font-size: 0.85em;
}

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

@media (max-width: 359px) {
  .app {
    padding: 0.75rem;
  }

  .times-table th,
  .times-table td {
    /* Behold mindst 44×44 px touch-mål også på smalle skærme */
    min-width: var(--touch);
    min-height: var(--touch);
    height: var(--touch);
    font-size: 0.85rem;
  }
}
