:root {
  --bg-top: #f6f7fb;
  --bg-bottom: #e6ebf3;
  --bg-accent: rgba(0, 113, 227, 0.08);
  --panel: rgba(255, 255, 255, 0.78);
  --panel-border: rgba(17, 24, 39, 0.08);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --warning: #ff9f0a;
  --alert: #ff453a;
  --done: #a1a1a6;
  --shadow: 0 18px 42px rgba(13, 23, 36, 0.09);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --viewport-min: min(100dvw, 100dvh);
  --widget-width: clamp(220px, calc(var(--viewport-min) * 0.64), 340px);
  --space-1: clamp(8px, calc(var(--widget-width) * 0.035), 12px);
  --space-2: clamp(10px, calc(var(--widget-width) * 0.05), 16px);
  --space-3: clamp(12px, calc(var(--widget-width) * 0.06), 18px);
  --radius-lg: clamp(18px, calc(var(--widget-width) * 0.08), 28px);
  --radius-md: clamp(12px, calc(var(--widget-width) * 0.055), 18px);
  --timer-size: clamp(146px, calc(var(--widget-width) * 0.6), 220px);
  --font-xs: clamp(0.66rem, calc(var(--widget-width) / 310), 0.8rem);
  --font-sm: clamp(0.78rem, calc(var(--widget-width) / 245), 0.96rem);
  --font-md: clamp(0.92rem, calc(var(--widget-width) / 200), 1.1rem);
  --font-lg: clamp(1.24rem, calc(var(--widget-width) / 132), 2rem);
  --font-xl: clamp(1.28rem, calc(var(--widget-width) / 120), 2.08rem);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "SF Pro Display", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  min-height: 100dvh;
  padding:
    calc(14px + var(--safe-top))
    calc(14px + var(--safe-right))
    calc(14px + var(--safe-bottom))
    calc(14px + var(--safe-left));
  overflow: auto;
  background:
    radial-gradient(circle at top center, rgba(255, 255, 255, 0.98), transparent 28%),
    radial-gradient(circle at bottom left, var(--bg-accent), transparent 24%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 28px);
  display: grid;
  place-items: center;
}

.widget-shell {
  width: min(100%, var(--widget-width));
  display: grid;
  gap: var(--space-2);
  container-type: inline-size;
}

.site-bar-inner {
  width: 100%;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(20px) saturate(1.25);
  box-shadow: 0 10px 24px rgba(13, 23, 36, 0.07);
}

.brand {
  font-size: var(--font-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.widget-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  justify-items: stretch;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(26px) saturate(1.22);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: var(--font-xl);
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-weight: 700;
}

.timer-form {
  display: grid;
  gap: var(--space-1);
}

.timer-overview {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
  min-width: 0;
}

.overview-pill {
  display: grid;
  gap: 3px;
  padding: var(--space-2);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.84);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.88),
    0 8px 20px rgba(13, 23, 36, 0.04);
}

.overview-pill strong {
  font-size: var(--font-sm);
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.overview-pill-muted {
  background: rgba(247, 248, 250, 0.74);
}

.overview-pill-wide {
  grid-column: 1 / -1;
}

.overview-label {
  font-size: var(--font-xs);
  color: var(--muted);
  letter-spacing: -0.01em;
}

.timer-list {
  display: grid;
  gap: 10px;
  max-height: min(56dvh, 420px);
  overflow: auto;
  padding-right: 4px;
}

.timer-list::-webkit-scrollbar,
.modal-panel::-webkit-scrollbar {
  width: 8px;
}

.timer-list::-webkit-scrollbar-thumb,
.modal-panel::-webkit-scrollbar-thumb {
  background: rgba(17, 24, 39, 0.14);
  border-radius: 999px;
}

.timer-item {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(248, 249, 251, 0.66));
  border: 1px solid rgba(17, 24, 39, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.timer-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.timer-item-index {
  margin: 0;
  font-size: var(--font-sm);
  font-weight: 600;
}

.field {
  display: grid;
  gap: 8px;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field span,
dt {
  font-size: var(--font-xs);
  letter-spacing: -0.01em;
  font-weight: 600;
  color: var(--muted);
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-sm);
  color: var(--text);
  line-height: 1.3;
}

.toggle-field input {
  width: 14px;
  height: 14px;
  margin: 0;
}

input {
  width: 100%;
  padding: 10px 11px;
  border-radius: 12px;
  border: 1px solid rgba(29, 29, 31, 0.08);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  -moz-appearance: textfield;
}

select {
  width: 100%;
  padding: 10px 11px;
  border-radius: 12px;
  border: 1px solid rgba(29, 29, 31, 0.08);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

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

input:focus,
select:focus {
  outline: none;
  border-color: rgba(0, 113, 227, 0.45);
  box-shadow:
    0 0 0 4px rgba(0, 113, 227, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

button {
  padding: 9px 10px;
  border-radius: 999px;
  border: 1px solid rgba(29, 29, 31, 0.08);
  cursor: pointer;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(241, 243, 247, 0.88));
  color: var(--text);
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease, box-shadow 160ms ease;
  box-shadow:
    0 4px 14px rgba(13, 23, 36, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  font-size: var(--font-sm);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: linear-gradient(180deg, #1e86f7, #0071e3);
  color: #fff;
  border-color: transparent;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
  margin: 0;
  width: 100%;
}

.status-grid div {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.78);
}

dd {
  margin: 4px 0 0;
  font-size: var(--font-md);
  font-weight: 600;
  letter-spacing: -0.02em;
  min-width: 0;
}

.status-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-value::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ring-color, var(--accent));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ring-color, var(--accent)) 16%, transparent);
}

.time-value {
  font-variant-numeric: tabular-nums;
}

.timer-panel {
  padding: var(--space-2);
  display: grid;
  gap: var(--space-2);
  width: 100%;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.94), transparent 40%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 248, 251, 0.56));
}

.timer-stage {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: calc(var(--space-2) + 2px) var(--space-2) var(--space-2);
  border-radius: calc(var(--radius-lg) + 2px);
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 255, 255, 0.98), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(241, 244, 248, 0.84));
  border: 1px solid rgba(255, 255, 255, 0.86);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.92),
    0 14px 28px rgba(13, 23, 36, 0.06);
}

.timer-card {
  width: 100%;
  min-width: 0;
  display: grid;
  place-items: center;
  min-height: calc(var(--timer-size) + (var(--space-2) * 0.5));
  transition: filter 220ms ease, color 220ms ease, transform 220ms ease;
}

.timer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
  width: 100%;
  max-width: clamp(58px, calc(var(--widget-width) * 0.23), 74px);
}

.floating-action {
  padding: 0;
  min-height: clamp(18px, calc(var(--widget-width) * 0.09), 26px);
  aspect-ratio: 1;
  place-self: center;
  width: 100%;
  max-width: clamp(19px, calc(var(--widget-width) * 0.09), 26px);
  display: grid;
  place-items: center;
  font-size: clamp(0.48rem, calc(var(--widget-width) / 470), 0.64rem);
  line-height: 1;
  box-shadow: 0 3px 8px rgba(13, 23, 36, 0.08);
}

.timer-face {
  position: relative;
  width: var(--timer-size);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 1) 0 38%, transparent 39%),
    radial-gradient(circle at center, rgba(29, 29, 31, 0.035) 65%, transparent 66%),
    linear-gradient(145deg, rgba(255, 255, 255, 1), rgba(239, 242, 246, 0.97));
  box-shadow:
    inset 0 4px 12px rgba(255, 255, 255, 1),
    inset 0 -12px 26px rgba(29, 29, 31, 0.06),
    0 16px 30px rgba(13, 23, 36, 0.12);
}

.face-rings,
.markers,
.progress-slice,
.pivot,
.center-readout {
  position: absolute;
}

.face-rings {
  inset: 10%;
  border-radius: 50%;
  border: clamp(7px, 1.5vw, 9px) solid rgba(29, 29, 31, 0.06);
}

.markers {
  inset: 7%;
  border-radius: 50%;
  background:
    repeating-conic-gradient(
      from -90deg,
      rgba(29, 29, 31, 0.44) 0deg 1.6deg,
      transparent 1.6deg 30deg
    );
  -webkit-mask: radial-gradient(circle, transparent 0 76%, #000 76% 81%, transparent 81%);
  mask: radial-gradient(circle, transparent 0 76%, #000 76% 81%, transparent 81%);
}

.progress-slice {
  inset: 12%;
  border-radius: 50%;
  background: conic-gradient(from -90deg, var(--ring-color, var(--accent)) 0deg 360deg, transparent 360deg);
  opacity: 0.34;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.34),
    inset 0 -10px 18px rgba(29, 29, 31, 0.06);
}

.pivot {
  width: clamp(9px, 1.4vw, 11px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.96);
  box-shadow:
    0 0 0 clamp(4px, 1vw, 5px) rgba(255, 255, 255, 0.86),
    0 2px 10px rgba(0, 0, 0, 0.08);
}

.center-readout {
  display: grid;
  gap: 4px;
  text-align: center;
  padding: 0;
  border: none;
  background: transparent;
  backdrop-filter: none;
}

.timer-name {
  font-size: var(--font-xs);
  color: var(--muted);
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

#large-time {
  font-size: var(--font-lg);
  line-height: 0.95;
  letter-spacing: -0.05em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  padding: 7px 10px;
  min-height: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(241, 243, 247, 0.88));
}

.icon-only {
  min-width: 28px;
  width: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: var(--font-md);
}

.remove-timer-button {
  padding: 6px 8px;
  min-height: auto;
  box-shadow: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(29, 29, 31, 0.18);
  backdrop-filter: blur(10px);
}

.modal-panel {
  position: relative;
  width: min(100vw - 24px, 420px);
  max-height: min(90dvh, 760px);
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 14px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.84);
  box-shadow: 0 22px 60px rgba(13, 23, 36, 0.16);
  backdrop-filter: blur(20px) saturate(1.2);
}

.modal-header {
  position: sticky;
  top: -16px;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin: -16px -16px 0;
  padding: 16px 16px 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.84));
  backdrop-filter: blur(18px);
}

.close-button {
  flex-shrink: 0;
}

.button-row-compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.state-normal {
  --ring-color: var(--accent);
}

.state-warning {
  --ring-color: var(--warning);
}

.state-alert {
  --ring-color: var(--alert);
}

.state-done {
  --ring-color: var(--done);
  filter: grayscale(1) saturate(0.45);
}

.state-alert .timer-card {
  transform: translateY(-1px);
}

@media (max-width: 900px) {
  .site-bar-inner {
    border-radius: 18px;
  }
}

@media (max-width: 520px) {
  body {
    padding:
      calc(10px + var(--safe-top))
      calc(10px + var(--safe-right))
      calc(10px + var(--safe-bottom))
      calc(10px + var(--safe-left));
  }

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

  .modal-panel {
    width: min(100vw - 16px, 420px);
    max-height: 92dvh;
    padding: 14px;
  }
}

@media (max-width: 360px), (max-height: 520px) {
  :root {
    --widget-width: min(100%, clamp(210px, calc(var(--viewport-min) * 0.78), 280px));
    --timer-size: clamp(132px, calc(var(--widget-width) * 0.56), 176px);
  }

  .timer-overview {
    grid-template-columns: 1fr;
  }

  .overview-pill-wide {
    grid-column: auto;
  }
}

@media (display-mode: standalone) {
  .app-shell {
    min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 28px);
  }
}
