/* FocusClock — mobile-first styles */

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

:root {
  --bg: #0e1220;
  --bg-glow: #182036;
  --panel-border: #2c3654;
  --chip-bg: #1a2340;
  --text: #eef1f8;
  --muted: #96a0b8;
  --sand: #ecb44f;
  --sand-deep: #d99a2b;
  --accent-ink: #241a05;
  --danger: #e4573f;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px)
           calc(env(safe-area-inset-right, 0px) + 20px)
           calc(env(safe-area-inset-bottom, 0px) + 16px)
           calc(env(safe-area-inset-left, 0px) + 20px);
  gap: 12px;
}

/* Header */
.header { text-align: center; }

.logo {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.logo-glyph { font-size: 1.1em; }

.tagline {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Main layout */
.main {
  flex: 1;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.hourglass {
  width: clamp(170px, 46vmin, 260px);
  height: auto;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
}

/* Falling sand stream animation */
.hourglass.running #stream {
  animation: sand-fall 0.5s linear infinite;
}

@keyframes sand-fall {
  to { stroke-dashoffset: -24; }
}

/* Completion shake */
.hourglass.done-shake {
  animation: shake 0.7s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-5deg); }
  40% { transform: rotate(5deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(3deg); }
}

.readout { text-align: center; }

.time {
  font-size: clamp(2.8rem, 14vw, 4.2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.timer-wrap.ending .time {
  color: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.status {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 1.4em;
}

/* Controls panel */
.panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.intervals {
  display: grid;
  grid-template-columns: repeat(3, minmax(56px, 88px));
  justify-content: center;
  gap: 8px;
}

.interval-btn {
  min-width: 56px;
  min-height: 56px;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  touch-action: manipulation;
}

.interval-btn span {
  font-size: 0.62rem;
  font-weight: 600;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

.interval-btn[aria-checked="true"] {
  background: linear-gradient(180deg, #f2c063, #e0a636);
  color: var(--accent-ink);
  border-color: transparent;
}

.interval-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.interval-btn.test {
  border-style: dashed;
  grid-column: 1 / -1;
  justify-self: center;
  min-width: 88px;
}

.interval-btn.test[aria-checked="true"] {
  border-style: solid;
}

.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn {
  border: none;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 16px 28px;
  cursor: pointer;
  width: min(100%, 340px);
  min-height: 54px;
  transition: transform 0.1s ease, filter 0.15s ease;
  touch-action: manipulation;
}

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

.btn-primary {
  background: linear-gradient(180deg, #f2c063, #e0a636);
  color: var(--accent-ink);
  box-shadow: 0 10px 24px rgba(236, 180, 79, 0.25);
}

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
}

.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-ghost.light { border-color: rgba(255, 255, 255, 0.5); color: #fff; }

.sessions {
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.notify-row {
  max-width: 340px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.notify-row.ok { color: #7fb583; }

.notify-row.warn { color: #d99a6b; }

.btn-notify {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-notify:hover { color: var(--text); border-color: var(--muted); }

.notify-hint {
  margin-top: 8px;
  color: #d99a6b;
  font-size: 0.8rem;
  line-height: 1.45;
}

.footer {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  max-width: 340px;
}

/* Time's up overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(228, 87, 63, 0.92);
}

.overlay.show { display: grid; animation: alarm-flash 1.1s ease-in-out infinite alternate; }

@keyframes alarm-flash {
  from { background: rgba(228, 87, 63, 0.94); }
  to   { background: rgba(236, 180, 79, 0.94); }
}

.overlay-card {
  background: #151a2b;
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

.overlay-bell {
  font-size: 3rem;
  animation: bell-swing 0.8s ease-in-out infinite;
}

@keyframes bell-swing {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(12deg); }
}

.overlay-card h2 { font-size: 1.8rem; margin: 8px 0 6px; }

.overlay-card p { color: var(--muted); margin-bottom: 22px; }

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .overlay.show, .overlay-bell, .timer-wrap.ending .time,
  .hourglass.running #stream, .hourglass.done-shake {
    animation: none;
  }
}

/* Landscape phones: put hourglass beside controls */
@media (orientation: landscape) and (max-height: 540px) {
  .app { gap: 6px; }
  .header { display: flex; align-items: baseline; gap: 10px; }
  .tagline { display: none; }
  .main {
    flex-direction: row;
    max-width: 760px;
    gap: 32px;
  }
  .hourglass { width: clamp(140px, 36vmin, 200px); }
  .time { font-size: clamp(2.2rem, 9vh, 3rem); }
  .footer { display: none; }
}

/* Tablets and desktop */
@media (min-width: 768px) and (min-height: 541px) {
  .logo { font-size: 1.6rem; }
  .tagline { font-size: 0.95rem; }
  .main { max-width: 520px; gap: 26px; }
  .hourglass { width: clamp(220px, 34vmin, 300px); }
  .time { font-size: clamp(3.2rem, 6vw, 4.6rem); }
}

/* Wide desktop: side-by-side layout */
@media (min-width: 1024px) and (min-height: 541px) {
  .main {
    flex-direction: row;
    max-width: 900px;
    gap: 64px;
  }
  .panel { max-width: 400px; }
}
