/* ============================================================
   Cali-Timer — stile
   Tema scuro, mobile first, pensato per iPhone
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --card: #131316;
  --card-soft: #0d0d0f;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text: #f4f4f5;
  --muted: #8e8e99;
  --muted-2: #63636d;
  --emerald: #b6ff00;
  --emerald-deep: #7cb300;
  --emerald-soft: rgba(182, 255, 0, 0.12);
  --orange: #fb923c;
  --sky: #38bdf8;
  --rose: #fb7185;
  --radius: 22px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html {
  background-color: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--font);
  background:
    radial-gradient(ellipse 90% 55% at 50% -12%, rgba(182, 255, 0, 0.16), transparent 62%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(56, 189, 248, 0.05), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input[type="range"] {
  font-family: inherit;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--emerald);
  outline-offset: 3px;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.icon-btn:active {
  transform: scale(0.94);
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--text);
    background: #1a1a1e;
  }
}

/* ---------------- Layout ---------------- */

.main {
  flex: 1;
  padding: calc(22px + env(safe-area-inset-top)) 18px 30px;
}

.view {
  animation: viewIn 0.32s cubic-bezier(0.22, 0.8, 0.3, 1) both;
}

@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-heading {
  margin: 2px 0 20px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--emerald);
}

.eyebrow-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(182, 255, 0, 0.8);
}

.section-heading h2 {
  margin: 9px 0 0;
  font-size: 29px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.section-sub {
  max-width: 340px;
  margin: 9px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------------- Card ---------------- */

.card {
  padding: 2px 17px;
  background: linear-gradient(180deg, rgba(23, 23, 27, 0.92) 0%, var(--card) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    0 18px 40px -24px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.card + .card,
.card + .presets-block,
.presets-block + .card,
.custom-card {
  margin-top: 14px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 2px;
  font-size: 12px;
  font-weight: 650;
  color: var(--emerald);
  background: none;
  border: 0;
  cursor: pointer;
}

.text-btn svg {
  width: 14px;
  height: 14px;
}

.text-btn:active {
  opacity: 0.65;
}

/* ---------------- Righe configurazione ---------------- */

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 17px 0;
}

.field + .field {
  border-top: 1px solid var(--line);
}

.field-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.field-label {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.field-hint {
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted-2);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  padding: 4px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.step-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 20px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.step-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

@media (hover: hover) {
  .step-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
  }
}

.step-btn-text {
  width: auto;
  min-width: 44px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.step-value {
  min-width: 56px;
  padding: 0 2px;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--text);
}

.stepper-time .step-value {
  min-width: 66px;
}

/* ---------------- Preset ---------------- */

.presets-block {
  margin-top: 20px;
}

.mini-label {
  display: block;
  margin: 0 2px 9px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease,
    transform 0.1s ease;
}

.chip:active {
  transform: scale(0.96);
}

.chip.is-active {
  color: #0b1000;
  background: linear-gradient(145deg, #e4ff8a, #b6ff00);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(182, 255, 0, 0.25);
}

@media (hover: hover) {
  .chip:hover {
    color: var(--text);
    border-color: var(--line-strong);
  }
  .chip.is-active:hover {
    color: #0b1000;
  }
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.switch span {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: #f4f4f5;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s cubic-bezier(0.3, 0.9, 0.4, 1.1), background 0.2s ease;
}

.switch[aria-checked="true"] {
  background: var(--emerald-deep);
  border-color: var(--emerald);
}

.switch[aria-checked="true"] span {
  transform: translateX(20px);
  background: #ffffff;
}

/* ---------------- Tempi personalizzati ---------------- */

.custom-card {
  padding: 17px;
}

.custom-list {
  max-height: 306px;
  margin-top: 9px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.custom-round {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.custom-round:first-child {
  border-top: 0;
}

.custom-round-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
}

.custom-round .stepper {
  padding: 3px;
  border-radius: 12px;
}

.custom-round .step-btn {
  width: 32px;
  height: 32px;
  font-size: 17px;
}

.custom-round .step-value {
  min-width: 58px;
  font-size: 15px;
}

/* ---------------- Riepilogo e CTA ---------------- */

.summary {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 8px;
  margin: 20px 0 14px;
  padding: 15px 14px;
  background: rgba(19, 19, 22, 0.75);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.summary-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-2);
  white-space: nowrap;
}

.summary-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--text);
}

.summary-divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.start-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 58px;
  padding: 0 20px;
  font-size: 16.5px;
  font-weight: 750;
  letter-spacing: -0.015em;
  color: #0b1000;
  background: linear-gradient(135deg, #e4ff8a 0%, #b6ff00 45%, #7cb300 100%);
  border: 0;
  border-radius: 18px;
  box-shadow:
    0 14px 34px -10px rgba(182, 255, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.start-btn svg {
  width: 20px;
  height: 20px;
}

.start-btn:active {
  transform: scale(0.98);
  filter: brightness(0.96);
  box-shadow: 0 8px 22px -10px rgba(182, 255, 0, 0.5);
}

.ios-hint {
  max-width: 330px;
  margin: 13px auto 0;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
  color: var(--muted-2);
}

/* ---------------- Timer attivo ---------------- */

body[data-view="timer"] .app-footer,
body[data-view="done"] .app-footer {
  display: none;
}

.timer-view {
  --ring-color: var(--emerald);
  --ring-glow: rgba(182, 255, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100dvh - 60px);
}

.timer-view[data-phase="prep"] {
  --ring-color: var(--orange);
  --ring-glow: rgba(251, 146, 60, 0.4);
}

.timer-view[data-phase="work"] {
  --ring-color: var(--emerald);
  --ring-glow: rgba(182, 255, 0, 0.4);
}

.timer-view[data-phase="rest"] {
  --ring-color: var(--sky);
  --ring-glow: rgba(56, 189, 248, 0.4);
}

.timer-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 10px;
}

.timer-head .icon-btn {
  position: absolute;
  left: 0;
}

.round-pill {
  padding: 8px 15px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.ring {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(244px, 74vw, 306px);
  aspect-ratio: 1;
  margin: 18px auto 0;
}

.ring::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--ring-glow), transparent 68%);
  opacity: 0.16;
  filter: blur(18px);
  transition: background 0.35s ease;
}

.ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  overflow: visible;
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.055);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--ring-color);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 829.38;
  stroke-dashoffset: 0;
  filter: drop-shadow(0 0 10px var(--ring-glow));
  transition: stroke-dashoffset 0.2s linear, stroke 0.35s ease,
    filter 0.35s ease;
}

.ring-center {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 0 18px;
  text-align: center;
}

.phase-label {
  min-height: 14px;
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ring-color);
  transition: color 0.35s ease;
}

.time-display {
  font-size: clamp(56px, 17.5vw, 76px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
  line-height: 1;
  color: #ffffff;
  transition: opacity 0.2s ease;
}

.next-label {
  min-height: 18px;
  max-width: 200px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.timer-view.is-paused .time-display {
  opacity: 0.42;
}

.timer-view.is-paused .ring-progress {
  animation: pausedPulse 1.6s ease-in-out infinite;
}

@keyframes pausedPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.timeline {
  display: flex;
  gap: 5px;
  width: 100%;
  max-width: 330px;
  margin: 22px auto 0;
  padding: 0 4px;
}

.timeline-segment {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.timeline-segment.is-done {
  background: rgba(182, 255, 0, 0.55);
}

.timeline-segment.is-current {
  background: var(--ring-color);
  box-shadow: 0 0 10px var(--ring-glow);
}

.timer-meta {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  max-width: 340px;
  margin: 24px auto 0;
  padding: 13px 16px;
  background: rgba(19, 19, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 17px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.meta-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.meta-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.meta-divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.controls {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(20px, 8vw, 36px);
  width: 100%;
  margin-top: auto;
  padding-top: 30px;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 56px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color 0.18s ease;
}

.control-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: transform 0.12s ease, background 0.18s ease;
}

.control-icon svg {
  width: 20px;
  height: 20px;
}

.control-btn:active .control-icon {
  transform: scale(0.92);
}

@media (hover: hover) {
  .control-btn:hover {
    color: var(--text);
  }
  .control-btn:hover .control-icon {
    background: #1a1a1e;
  }
}

.control-primary .control-icon {
  width: 70px;
  height: 70px;
  color: #0b1000;
  background: linear-gradient(135deg, #e4ff8a, #b6ff00 55%, #7cb300);
  border: 0;
  box-shadow:
    0 12px 30px -8px rgba(182, 255, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.control-primary .control-icon svg {
  width: 26px;
  height: 26px;
}

.control-primary {
  color: var(--text);
}

.control-primary .icon-play {
  display: none;
}

.timer-view.is-paused .control-primary .icon-pause {
  display: none;
}

.timer-view.is-paused .control-primary .icon-play {
  display: block;
}

/* ---------------- Completato ---------------- */

.done-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 26px;
  text-align: center;
}

.done-badge {
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  margin-bottom: 24px;
  color: var(--emerald);
  background: var(--emerald-soft);
  border: 1px solid rgba(182, 255, 0, 0.28);
  border-radius: 30px;
  box-shadow:
    0 0 60px rgba(182, 255, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: badgeIn 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.done-badge svg {
  width: 38px;
  height: 38px;
}

@keyframes badgeIn {
  from {
    opacity: 0;
    transform: scale(0.6) rotate(-8deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.done-view h2 {
  margin: 10px 0 0;
  font-size: 31px;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.done-sub {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

.done-stats {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  margin: 28px 0 26px;
  padding: 19px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
}

.done-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.done-view .start-btn {
  max-width: 360px;
}

.ghost-btn {
  width: 100%;
  max-width: 360px;
  height: 50px;
  margin-top: 10px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.ghost-btn:active {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

/* ---------------- Footer ---------------- */

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted-2);
}

.footer-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--emerald);
}

/* ---------------- Adattamenti ---------------- */

@media (max-width: 359px) {
  .field {
    flex-wrap: wrap;
  }

  .field-copy {
    flex: 1 1 100%;
  }

  .field .stepper {
    width: 100%;
    justify-content: space-between;
  }

  .step-value {
    flex: 1;
  }
}

/* Schermi bassi (iPhone SE e simili): timer più compatto */
@media (max-height: 740px) {
  .ring {
    width: clamp(206px, 61vw, 248px);
    margin-top: 8px;
  }

  .time-display {
    font-size: clamp(48px, 15vw, 62px);
  }

  .phase-label {
    font-size: 9.5px;
  }

  .timeline {
    margin-top: 13px;
  }

  .timer-meta {
    margin-top: 15px;
    padding: 10px 16px;
  }

  .controls {
    padding-top: 16px;
  }

  .control-primary .control-icon {
    width: 64px;
    height: 64px;
  }

  .control-icon {
    width: 50px;
    height: 50px;
  }
}

@media (min-width: 640px) {
  body {
    padding: 0;
  }

  .app {
    background: rgba(10, 10, 11, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.04);
    border-right: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 90px rgba(0, 0, 0, 0.55);
  }

  .main {
    padding-left: 22px;
    padding-right: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
