:root {
  --bg: #111318;
  --panel: #1c1f26;
  --text: #f5f6f8;
  --muted: #a7adba;
  --accent: #3949ab;
  --overlay-bg: rgba(0, 0, 0, 0.7);
  --surface-border: rgba(255, 255, 255, 0.12);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --border: #333846;
  --border-strong: #565758;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.view {
  width: 100%;
  height: 100%;
}

.view[hidden] {
  display: none !important;
}

/* Welcome screen */
.view-welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.welcome-content {
  max-width: 32rem;
  text-align: center;
}

.app-title {
  font-size: 3.5rem;
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}

.app-description {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.5;
  margin: 0 0 2.5rem;
}

.start-btn {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1.25rem 3.5rem;
  border: none;
  border-radius: 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.start-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

.start-btn:active {
  transform: translateY(0);
}

/* Header actions (global, top-right) */
.header-actions {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top, 0px));
  right: calc(1rem + env(safe-area-inset-right, 0px));
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Main colour-cycling screen */
.view-main {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--flash-colour, #e53935);
  transition: background-color 0.25s ease;
}

.colour-history {
  position: absolute;
  top: calc(1.25rem + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.9rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 2rem;
  z-index: 10;
}

.colour-history.hidden,
.colour-history[hidden] {
  display: none !important;
}

.colour-history li {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.5);
  flex: none;
}

.colour-history li:last-child {
  width: 1.4rem;
  height: 1.4rem;
  border-color: rgba(255, 255, 255, 0.9);
}

.timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  z-index: 5;
}

.timer {
  font-size: clamp(4rem, 18vw, 10rem);
  font-weight: 800;
  color: rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
  user-select: none;
  pointer-events: none;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.laps-container {
  max-height: 220px;
  width: min(90vw, 360px);
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 1rem;
  padding: 0.5rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.laps-container.hidden {
  display: none !important;
}

.laps-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  gap: 8px;
}

.lap-num {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  min-width: 50px;
}

.lap-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

.lap-split {
  color: #81c784;
  font-weight: 700;
}

.lap-total {
  color: rgba(255, 255, 255, 0.85);
  font-variant-numeric: tabular-nums;
}

.main-actions {
  position: absolute;
  bottom: 2.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 10;
}

.lap-btn,
.stop-btn,
.resume-btn,
.restart-btn,
.end-btn {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.9rem 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 1rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease, transform 0.1s ease;
}

.lap-btn {
  background: rgba(46, 125, 50, 0.75);
  color: #fff;
}

.lap-btn:hover {
  background: rgba(46, 125, 50, 0.9);
}

.lap-btn:active {
  transform: scale(0.96);
}

.lap-btn.hidden {
  display: none !important;
}

.stop-btn {
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

.stop-btn:hover {
  background: rgba(0, 0, 0, 0.75);
}

.stop-btn:active {
  transform: scale(0.96);
}

.stop-btn.hidden {
  display: none !important;
}

.resume-btn {
  background: rgba(25, 118, 210, 0.8);
  color: #fff;
}

.resume-btn:hover {
  background: rgba(25, 118, 210, 0.95);
}

.resume-btn:active {
  transform: scale(0.96);
}

.resume-btn.hidden {
  display: none !important;
}

.restart-btn {
  background: rgba(211, 47, 47, 0.8);
  color: #fff;
}

.restart-btn:hover {
  background: rgba(211, 47, 47, 0.95);
}

.restart-btn:active {
  transform: scale(0.96);
}

.restart-btn.hidden {
  display: none !important;
}

.end-btn {
  background: rgba(100, 110, 125, 0.75);
  color: #fff;
}

.end-btn:hover {
  background: rgba(100, 110, 125, 0.95);
}

.end-btn:active {
  transform: scale(0.96);
}

.end-btn.hidden {
  display: none !important;
}

/* Modal windows */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: 1rem;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 28rem;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 1rem;
  padding: 0 1.5rem 1.5rem;
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.15s ease;
}

@keyframes modal-in {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  padding-top: 1.5rem;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
  padding-right: 2rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.modal-close-btn {
  position: absolute;
  top: 1.5rem;
  right: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: background 0.15s ease;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.modal-content p {
  line-height: 1.5;
  font-size: 0.95rem;
  color: var(--text);
  margin: 0 0 1rem;
}

.modal-content h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 1.2rem 0 0.6rem;
}

.modal-content ul {
  padding-left: 1.2rem;
  margin: 0 0 1.2rem;
}

.modal-content li {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--muted);
}

.modal-content li strong {
  color: var(--text);
}

.btn-primary,
.btn-secondary {
  padding: 0.65rem 1.3rem;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.field {
  display: block;
  margin-bottom: 1.5rem;
}

.field > span {
  display: block;
  margin-bottom: 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border-radius: 0.5rem;
  border: 1px solid #333846;
  background: #12141a;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}

.field input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 73, 171, 0.3);
}

/* Preset timing pills */
.preset-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.preset-btn {
  flex: 1;
  min-width: 48px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #12141a;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.preset-btn:hover {
  background: #1c212c;
  border-color: var(--muted);
}

.preset-btn:active {
  transform: scale(0.97);
}

.preset-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(57, 73, 171, 0.4);
}

/* Segmented control for colour order */
.order-field {
  border: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.segmented-control {
  display: flex;
  gap: 6px;
  background: #12141a;
  padding: 4px;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
}

.segmented-btn {
  flex: 1;
  min-height: 44px;
  padding: 10px 14px;
  border: none;
  border-radius: 0.45rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.segmented-btn:hover {
  color: var(--text);
}

.segmented-btn:active {
  transform: scale(0.98);
}

.segmented-btn.selected {
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.colour-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.colour-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  background: #12141a;
  border: 1px solid #333846;
  border-radius: 2rem;
  padding: 0.35rem 0.6rem 0.35rem 0.45rem;
}

.colour-swatch {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex: none;
}

.colour-chip button {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s ease, color 0.15s ease;
}

.colour-chip button:hover:not(:disabled) {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

.colour-chip button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.add-colour {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.add-colour input[type="color"] {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 2px;
  background: #12141a;
  cursor: pointer;
}

.add-colour button {
  min-height: 44px;
  padding: 0.65rem 1.2rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: #2a2f3a;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.add-colour button:hover {
  background: #333846;
  border-color: var(--muted);
}

.add-colour button:active {
  transform: scale(0.98);
}

.settings-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
  gap: 1rem;
}

.settings-actions button {
  min-height: 44px;
  padding: 0.65rem 1.2rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.reset-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease;
}

.reset-btn:hover {
  color: #fff;
}

.close-btn {
  background: var(--accent);
  color: #fff;
}

.close-btn:hover {
  filter: brightness(1.1);
}

/* Footer (hidden during the full-screen colour-cycling view) */
#site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
  border-top: 1px solid #2a2f3a;
  z-index: 5;
}

@media (max-width: 380px) {
  #site-footer {
    font-size: 0.7rem;
  }
}

#site-footer a {
  color: var(--muted);
  font-weight: bold;
  text-decoration: none;
}

#site-footer a:hover {
  text-decoration: underline;
}

.footer-version {
  opacity: 0.6;
}

.footer-version::before {
  content: " \00b7 "; /* middot separator, matches the em-space rhythm of the rest of the line */
}
