:root {
  color-scheme: dark;
  --bg: #10130f;
  --panel: #171b16;
  --panel-2: #20251e;
  --line: #363d32;
  --muted: #9ba495;
  --text: #f4f6f1;
  --lime: #c7ff42;
  --lime-dark: #18220c;
  --green: #69d27c;
  --orange: #ffb44a;
  --red: #ff6d61;
  --item-width: clamp(92px, 12vw, 180px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button,
textarea,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.topbar {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 19, 15, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand > div {
  min-width: 0;
}

.brand-logo {
  flex: 0 0 auto;
  width: auto;
  height: 68px;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.4));
  user-select: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: min(48vw, 720px);
  overflow: hidden;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.toolbar-button,
.secondary-button,
.primary-button,
.danger-button,
.icon-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 18px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.toolbar-button--primary,
.primary-button {
  border-color: var(--lime);
  background: var(--lime);
  color: #11150e;
}

.timer-shell {
  height: calc(100dvh - 84px);
  padding: 14px;
}

.grid-wrap {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  scrollbar-color: #4c5547 transparent;
}

.timer-grid {
  --header-row-size: 1.85fr;
  --action-row-size: 1.6fr;
  position: relative;
  display: grid;
  grid-template-columns: var(--item-width) repeat(var(--participant-count), minmax(0, 1fr));
  grid-template-rows:
    minmax(0, var(--header-row-size))
    repeat(var(--workout-count), minmax(0, 1fr))
    minmax(0, var(--action-row-size));
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.empty-workout {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: 28px;
  text-align: center;
}

.empty-workout__card {
  max-width: 560px;
}

.empty-workout h2 {
  margin-bottom: 10px;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
}

.empty-workout p {
  margin-bottom: 22px;
  color: var(--muted);
  font-size: clamp(1rem, 1.7vw, 1.2rem);
  line-height: 1.5;
}

.grid-cell {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: clamp(2px, 0.45vw, 8px);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.corner-cell,
.participant-header {
  z-index: 5;
  min-height: 0;
  background: #1c211a;
  box-shadow: 0 1px 0 var(--line);
}

.participant-header.is-finished-header {
  background: #253425;
  box-shadow:
    inset 0 0 0 2px rgba(105, 210, 124, 0.45),
    0 1px 0 var(--line);
}

.corner-cell {
  z-index: 8;
  align-items: flex-end;
  justify-content: flex-start;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.participant-header {
  position: relative;
  flex-direction: column;
  gap: clamp(1px, 0.35vh, 5px);
  padding-top: clamp(3px, 0.5vh, 7px);
  padding-bottom: clamp(3px, 0.5vh, 7px);
}

.timer-grid.is-many-participants {
  --header-row-size: 3.15fr;
  --action-row-size: 1.8fr;
}

.timer-grid.is-many-participants .participant-header {
  gap: 2px;
  padding: 4px 2px;
}

.timer-grid.is-many-participants .participant-name-row {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  align-items: center;
}

.timer-grid.is-many-participants .participant-name {
  display: -webkit-box;
  width: 100%;
  max-height: 3.15em;
  overflow: hidden;
  font-size: clamp(0.66rem, 0.88vw, 0.95rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-align: center;
  text-overflow: clip;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.timer-grid.is-many-participants .participant-meta {
  width: 100%;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 1px;
}

.timer-grid.is-many-participants .participant-clock {
  font-size: clamp(0.58rem, 0.72vw, 0.76rem);
  line-height: 1;
}

.timer-grid.is-many-participants .reset-button {
  width: min(58px, 88%);
  min-width: 0;
  height: 19px;
  border-radius: 5px;
  font-size: clamp(0.45rem, 0.55vw, 0.58rem);
  line-height: 1;
}

.timer-grid.is-many-participants .finish-flag {
  position: absolute;
  top: 3px;
  right: 3px;
  font-size: clamp(0.7rem, 0.85vw, 0.9rem);
}

.timer-grid.is-max-participants {
  --header-row-size: 3.6fr;
}

.timer-grid.is-max-participants .participant-name {
  max-height: 4.1em;
  font-size: clamp(0.62rem, 0.78vw, 0.84rem);
  line-height: 1.02;
  -webkit-line-clamp: 4;
}

.participant-name-row {
  display: flex;
  max-width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: clamp(3px, 0.45vw, 8px);
}

.participant-name {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(0.74rem, 1.55vw, 1.35rem);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finish-flag {
  display: inline-grid;
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: clamp(0.82rem, 1.45vw, 1.35rem);
  line-height: 1;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

.finish-flag:active {
  transform: scale(0.9);
}

.participant-clock {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(0.65rem, 1.15vw, 1rem);
}

.participant-clock.is-running {
  color: var(--lime);
}

.participant-meta {
  display: flex;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 0.7vw, 12px);
}

.reset-button {
  min-width: clamp(54px, 4.6vw, 76px);
  min-height: 0;
  height: clamp(22px, 2.8vh, 30px);
  border: 1px solid #495044;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: clamp(0.52rem, 0.75vw, 0.7rem);
  font-weight: 850;
  cursor: pointer;
}

.reset-button:active {
  border-color: var(--red);
  color: var(--red);
}

.workout-name {
  z-index: 3;
  justify-content: flex-start;
  background: #1c211a;
  color: #d7dcd3;
  gap: clamp(2px, 0.35vw, 6px);
  font-size: clamp(0.57rem, 0.95vw, 0.9rem);
  font-weight: 850;
  text-transform: uppercase;
}

.workout-name span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workout-number {
  flex: 0 0 auto;
  width: clamp(17px, 1.8vw, 25px);
  color: #737d6e;
  font-size: clamp(0.48rem, 0.65vw, 0.68rem);
}

.time-cell {
  position: relative;
  flex-direction: column;
  gap: clamp(0px, 0.2vh, 3px);
  font-variant-numeric: tabular-nums;
}

.time-cell.is-complete {
  background: rgba(105, 210, 124, 0.1);
}

.is-finished-column-cell {
  opacity: 0.42;
  filter: blur(1.4px) grayscale(0.35);
}

.finish-column-overlay {
  position: absolute;
  z-index: 15;
  display: flex;
  min-width: 0;
  min-height: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: clamp(3px, 0.7vh, 10px);
  border-right: 1px solid rgba(105, 210, 124, 0.65);
  border-left: 1px solid rgba(105, 210, 124, 0.65);
  background: rgba(30, 74, 38, 0.48);
  color: #f6fff3;
  text-align: center;
  cursor: pointer;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  font: inherit;
}

.finish-column-flag {
  font-size: clamp(1.7rem, 4vw, 4rem);
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.55));
}

.finish-column-label {
  color: var(--green);
  font-size: clamp(0.7rem, 1.2vw, 1rem);
  font-weight: 950;
  letter-spacing: 0.18em;
}

.finish-column-overlay strong {
  max-width: 100%;
  padding: 0 6px;
  overflow: hidden;
  font-size: clamp(1.15rem, 3vw, 2.8rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-overflow: ellipsis;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.65);
  white-space: nowrap;
}

.finish-column-hint {
  color: rgba(246, 255, 243, 0.82);
  font-size: clamp(0.55rem, 0.8vw, 0.78rem);
  font-weight: 800;
}

.finish-column-overlay:active {
  background: rgba(45, 102, 55, 0.58);
}

.time-cell.is-active {
  background: var(--lime-dark);
  box-shadow: inset 0 0 0 clamp(1px, 0.2vw, 3px) var(--lime);
}

.time-cell.is-next::after {
  content: "VOLGENDE";
  color: #697164;
  font-size: clamp(0.43rem, 0.55vw, 0.64rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.cell-time {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(0.62rem, 1.4vw, 1.3rem);
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-label {
  color: var(--lime);
  font-size: clamp(0.42rem, 0.58vw, 0.66rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.action-label,
.participant-action {
  z-index: 5;
  min-height: 0;
  border-bottom: 0;
  background: #151914;
  box-shadow: 0 -1px 0 var(--line);
}

.action-label {
  z-index: 8;
  align-items: flex-start;
  flex-direction: column;
  color: var(--muted);
  font-size: clamp(0.5rem, 0.7vw, 0.72rem);
  font-weight: 850;
}

.action-label strong {
  color: var(--text);
  font-size: clamp(0.58rem, 0.85vw, 0.86rem);
}

.lap-button {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 14px;
  background: var(--lime);
  color: #12160f;
  font-size: clamp(0.72rem, 1.55vw, 1.35rem);
  font-weight: 950;
  text-transform: uppercase;
  cursor: pointer;
}

.timer-grid.is-dense .grid-cell {
  padding-top: 1px;
  padding-bottom: 1px;
}

.timer-grid.is-dense .action-label span,
.timer-grid.is-ultra-dense .active-label,
.timer-grid.is-ultra-dense .time-cell.is-next::after {
  display: none;
}

.timer-grid.is-ultra-dense .participant-header {
  gap: 0;
}

.timer-grid.is-ultra-dense .workout-number {
  display: none;
}

.timer-grid.is-ultra-dense .reset-button {
  height: 20px;
  border-radius: 5px;
}

.lap-button.is-running {
  background: var(--orange);
}

.lap-button.is-finished {
  background: #30362d;
  color: #8d9788;
}

.lap-button:active:not(:disabled) {
  transform: scale(0.97);
  filter: brightness(1.12);
}

.settings-dialog {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid #4a5345;
  border-radius: 20px;
  background: #191d18;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

.settings-dialog::backdrop {
  background: rgba(4, 6, 4, 0.82);
  backdrop-filter: blur(5px);
}

.settings-dialog.is-required [data-close-settings] {
  display: none;
}

.confirm-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid #596252;
  border-radius: 20px;
  background: #191d18;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.65);
}

.confirm-dialog::backdrop {
  background: rgba(4, 6, 4, 0.78);
  backdrop-filter: blur(5px);
}

.confirm-dialog__content {
  padding: clamp(22px, 3vw, 34px);
}

.confirm-dialog h2 {
  font-size: clamp(1.35rem, 2.5vw, 1.8rem);
}

.confirm-message {
  margin: 14px 0 24px;
  color: #c8cec3;
  font-size: clamp(1rem, 1.6vw, 1.15rem);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-actions button {
  min-width: 130px;
}

.danger-button--filled {
  border-color: var(--red);
  background: var(--red);
  color: #17100f;
}

.settings-dialog form {
  padding: 24px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.new-workout-button {
  border-color: rgba(199, 255, 66, 0.6);
  color: var(--lime);
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--lime);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.dialog-header h2 {
  font-size: 1.7rem;
}

.icon-button {
  width: 48px;
  padding: 0;
  font-size: 1.75rem;
}

.dialog-help {
  margin: 18px 0;
  color: var(--muted);
  line-height: 1.5;
}

.settings-columns {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 18px;
}

.workout-title-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  font-weight: 850;
}

.workout-library {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px 14px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(199, 255, 66, 0.035);
}

.workout-library > div:first-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-weight: 850;
}

.library-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.library-actions button {
  min-height: 48px;
  white-space: nowrap;
}

.danger-button {
  border-color: rgba(255, 109, 97, 0.5);
  background: transparent;
  color: var(--red);
}

.library-status {
  grid-column: 1 / -1;
  min-height: 1.2em;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
}

.library-status.is-error {
  color: var(--red);
}

.settings-columns label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 850;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px;
  background: #10130f;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
}

textarea {
  resize: vertical;
}

textarea:focus,
input:focus,
select:focus {
  outline: 2px solid var(--lime);
  outline-offset: 1px;
}

.form-error {
  min-height: 24px;
  margin: 12px 0 4px;
  color: var(--red);
  font-weight: 800;
}

.dialog-actions {
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    min-height: 76px;
    padding: 10px 12px;
  }

  .brand p,
  #fullscreenButton {
    display: none;
  }

  .toolbar-button {
    min-height: 46px;
    padding: 0 12px;
    font-size: 0.78rem;
  }

  .timer-shell {
    height: calc(100dvh - 76px);
    padding: 8px;
  }

  .settings-columns {
    grid-template-columns: 1fr;
  }

  .workout-library {
    grid-template-columns: 1fr;
  }

  .library-actions {
    align-items: stretch;
  }

  .library-actions button {
    flex: 1;
    padding: 0 8px;
    white-space: normal;
  }

  .new-workout-button {
    min-height: 42px;
    padding: 0 10px;
    font-size: 0.75rem;
  }
}

@media (max-height: 900px) {
  .topbar {
    height: 66px;
    min-height: 0;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .brand-logo {
    height: 54px;
  }

  .brand p {
    display: none;
  }

  .toolbar-button {
    min-height: 42px;
  }

  .timer-shell {
    height: calc(100dvh - 66px);
    padding: 8px;
  }
}

@media (max-height: 650px) {
  .topbar {
    height: 54px;
    min-height: 0;
  }

  .brand-logo {
    height: 44px;
  }

  h1 {
    font-size: 1.05rem;
  }

  .toolbar-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .timer-shell {
    height: calc(100dvh - 54px);
    padding: 5px;
  }
}

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