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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  background: #000;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow-x: hidden;
}

/* ── Display page ── */

.display-page {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  overflow: hidden;
}

.display-stage {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.display-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 3vh, 2rem);
  transform-origin: center center;
  will-change: transform;
}

.display-session {
  font-size: clamp(1.25rem, 5vmin, 5rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  line-height: 1.15;
  max-width: 92vw;
  word-break: break-word;
  overflow-wrap: break-word;
  flex-shrink: 0;
}

.display-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.15rem, 1.5vmin, 0.75rem);
  font-variant-numeric: tabular-nums;
  max-width: 96vw;
  line-height: 1;
}

.display-minutes,
.display-seconds {
  font-size: clamp(3.5rem, 24vmin, 32rem);
  font-weight: 700;
  line-height: 0.9;
  flex-shrink: 1;
  min-width: 0;
}

.display-separator {
  font-size: clamp(2.5rem, 18vmin, 26rem);
  font-weight: 300;
  line-height: 0.9;
  opacity: 0.7;
  flex-shrink: 0;
  align-self: center;
  padding-bottom: 0.05em;
}

/* Tablet portrait (iPad, dll.) */
@media (max-width: 1024px) and (orientation: portrait) {
  .display-session {
    font-size: clamp(1.1rem, 4.5vmin, 3rem);
  }

  .display-minutes,
  .display-seconds {
    font-size: clamp(3rem, 20vmin, 12rem);
  }

  .display-separator {
    font-size: clamp(2rem, 15vmin, 9rem);
  }
}

/* Tablet landscape */
@media (max-width: 1024px) and (orientation: landscape) {
  .display-content {
    flex-direction: row;
    gap: clamp(1rem, 4vw, 3rem);
  }

  .display-session {
    font-size: clamp(1rem, 4vmin, 2.5rem);
    max-width: 35vw;
    text-align: left;
  }

  .display-minutes,
  .display-seconds {
    font-size: clamp(3rem, 22vmin, 14rem);
  }

  .display-separator {
    font-size: clamp(2rem, 16vmin, 10rem);
  }
}

/* Phone */
@media (max-width: 600px) {
  .display-page {
    gap: 1rem;
  }

  .display-session {
    font-size: clamp(1rem, 6vw, 1.75rem);
    letter-spacing: 0.04em;
  }

  .display-minutes,
  .display-seconds {
    font-size: clamp(2.75rem, 22vw, 6rem);
  }

  .display-separator {
    font-size: clamp(2rem, 16vw, 4.5rem);
  }
}

/* Very short screens */
@media (max-height: 500px) and (orientation: landscape) {
  .display-content {
    flex-direction: row;
    gap: 1.5rem;
  }

  .display-session {
    font-size: clamp(0.9rem, 5vh, 1.5rem);
    max-width: 40vw;
  }

  .display-minutes,
  .display-seconds {
    font-size: clamp(2.5rem, 18vh, 8rem);
  }

  .display-separator {
    font-size: clamp(2rem, 14vh, 6rem);
  }
}

/* ── Controller page ── */

.controller-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2rem;
  gap: 2rem;
}

.controller-header {
  text-align: center;
}

.session-title-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.session-title-edit {
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
}

.session-display {
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
  padding: 0.5rem 1rem;
  word-break: break-word;
}

.session-title-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.btn-session-action {
  padding: 0.45rem 1.25rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-session-action:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.btn-session-save {
  border-color: #fff;
  background: #fff;
  color: #000;
}

.btn-session-save:hover {
  background: rgba(255, 255, 255, 0.9);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.settings-panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn-reset-defaults {
  padding: 0.65rem 1.5rem;
  border-radius: 999px;
  border: 1px solid #ef476f;
  background: transparent;
  color: #ef476f;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-reset-defaults:hover {
  background: rgba(239, 71, 111, 0.12);
}

.settings-panel-hint {
  font-size: 0.75rem;
  opacity: 0.45;
  text-align: center;
  max-width: 320px;
}

.session-input {
  width: 100%;
  max-width: 700px;
  background: transparent;
  border: none;
  border-bottom: 2px solid #fff;
  color: #fff;
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  outline: none;
}

.session-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.controller-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.controls-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.btn-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-circle:hover {
  background: #fff;
  color: #000;
}

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

.presets-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.btn-preset {
  min-width: 120px;
  padding: 1rem 1.5rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: transparent;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-preset:hover {
  background: #fff;
  color: #000;
}

.timer-boxes {
  display: flex;
  gap: 1.5rem;
  align-items: stretch;
}

.timer-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.timer-box-label {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: lowercase;
}

.timer-box-input {
  width: clamp(140px, 28vw, 280px);
  height: clamp(160px, 35vw, 320px);
  border: 3px solid #fff;
  background: transparent;
  color: #fff;
  font-size: clamp(4rem, 12vw, 9rem);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
  -moz-appearance: textfield;
}

.timer-box-input::-webkit-outer-spin-button,
.timer-box-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.timer-box-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.color-panel {
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding-top: 1.5rem;
}

.color-panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  opacity: 0.6;
  margin-bottom: 1.25rem;
}

.color-targets {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.color-target-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: transparent;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.color-target-btn:hover {
  background: #fff;
  color: #000;
}

.color-target-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.color-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.color-modal[hidden] {
  display: none;
}

.color-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.color-modal-box {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: #111;
  border: 2px solid #fff;
  border-radius: 12px;
  padding: 1.5rem;
}

.color-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1.25rem;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.color-swatch {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s, border-color 0.1s;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #000, 0 0 0 4px #fff;
}

.color-modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.btn-modal {
  padding: 0.6rem 1.5rem;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid #fff;
}

.btn-modal-cancel {
  background: transparent;
  color: #fff;
}

.btn-modal-save {
  background: #fff;
  color: #000;
}

.controller-footer {
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.4;
}

/* ── Password page ── */

.password-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 2rem;
}

.password-title {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.password-code-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.25rem 2rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
}

.password-code-label {
  font-size: 0.85rem;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.password-code-value {
  font-size: clamp(1.25rem, 5vw, 2rem);
  font-weight: 700;
  word-break: break-all;
  text-align: center;
}

.password-subtitle {
  font-size: 0.9rem;
  opacity: 0.5;
  text-align: center;
  max-width: 280px;
}

/* ── Auth gate (display / controller) ── */

.gate-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem;
}

.gate-title {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.gate-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 320px;
}

.gate-label {
  font-size: 0.9rem;
  opacity: 0.7;
}

.password-field {
  position: relative;
  width: 100%;
}

.password-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.password-toggle:hover {
  color: #fff;
}

.password-toggle svg {
  width: 1.35rem;
  height: 1.35rem;
}

.gate-input {
  width: 100%;
  padding: 0.85rem 3rem 0.85rem 1rem;
  border: 2px solid #fff;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  outline: none;
}

.gate-error {
  color: #ef476f;
  font-size: 0.9rem;
}

.password-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 320px;
}

.password-input-label {
  font-size: 0.9rem;
  opacity: 0.7;
}

.password-input {
  width: 100%;
  padding: 0.85rem 3rem 0.85rem 1rem;
  border: 2px solid #fff;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  outline: none;
}

.password-error {
  color: #ef476f;
  font-size: 0.9rem;
}

.btn-connect {
  padding: 0.85rem 2.5rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: #fff;
  color: #000;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

/* ── Adjust display modal ── */

.adjust-modal[hidden] {
  display: none;
}

.adjust-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.adjust-modal-box {
  max-width: 340px;
}

.adjust-field {
  margin-bottom: 1.5rem;
}

.adjust-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  opacity: 0.8;
}

.adjust-range {
  width: 100%;
  accent-color: #fff;
  cursor: pointer;
}

.adjust-arrows {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.adjust-arrows-mid {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.adjust-arrow {
  width: 52px;
  height: 52px;
  border: 2px solid #fff;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.adjust-arrow:hover {
  background: #fff;
  color: #000;
}

.adjust-arrow-reset {
  font-size: 1.25rem;
}

@media (max-width: 600px) {
  .controller-body {
    flex-direction: column;
  }

  .controls-column {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .presets-column {
    grid-template-columns: 1fr 1fr;
    width: 100%;
    max-width: 280px;
  }

  .color-palette {
    grid-template-columns: repeat(6, 1fr);
  }

  .btn-circle {
    width: 64px;
    height: 64px;
    font-size: 0.75rem;
  }
}
