:root {
  --bg: #111113;
  --surface-1: #18181c;
  --surface-2: #1e1e24;
  --border: rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.13);
  --text-hi: #f2f2f5;
  --text-mid: #9898a8;
  --text-lo: #4e4e62;
  --accent-a: #ef4444;
  --accent-b: #f97316;
  --accent: #ef4444;
  --ring-c: 741.42;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-xl: 28px;
  --gap: 12px;
  --f-ui: "Hanken Grotesk", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", "Fira Code", monospace;
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-mode="pomodoro"] {
  --accent-a: #ef4444;
  --accent-b: #f97316;
  --accent: #ef4444;
}
html[data-mode="short-break"] {
  --accent-a: #14b8a6;
  --accent-b: #06b6d4;
  --accent: #14b8a6;
}
html[data-mode="long-break"] {
  --accent-a: #8b5cf6;
  --accent-b: #6366f1;
  --accent: #8b5cf6;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  height: 100%;
}

body {
  font-family: var(--f-ui);
  background: var(--bg);
  color: var(--text-hi);
  min-height: 100vh;
  display: grid;
  place-items: start center;
  background-image:
    radial-gradient(
      ellipse 70% 40% at 50% 0%,
      rgba(239, 68, 68, 0.055) 0%,
      transparent 65%
    ),
    radial-gradient(
      ellipse 50% 60% at 80% 100%,
      rgba(99, 102, 241, 0.03) 0%,
      transparent 60%
    );
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

html[data-mode="short-break"] body {
  background-image: radial-gradient(
    ellipse 70% 40% at 50% 0%,
    rgba(20, 184, 166, 0.06) 0%,
    transparent 65%
  );
}
html[data-mode="long-break"] body {
  background-image: radial-gradient(
    ellipse 70% 40% at 50% 0%,
    rgba(139, 92, 246, 0.06) 0%,
    transparent 65%
  );
}

button {
  font-family: var(--f-ui);
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.is-hidden {
  display: none !important;
}

.app {
  width: min(100%, 520px);
  padding: 1.5rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.brand-tomato {
  width: 28px;
  height: 28px;
}
.brand-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-hi);
  letter-spacing: -0.03em;
}
.brand-text em {
  font-style: normal;
  color: var(--accent);
  transition: color 0.4s;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.install-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.28rem 0.7rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.03em;
  transition:
    background 0.2s,
    border-color 0.2s,
    transform 0.15s var(--ease-bounce);
}
.install-btn svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}
.install-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.session-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 0.28rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-mid);
  letter-spacing: 0.04em;
}
.session-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulsePoint 2s ease-in-out infinite;
}
@keyframes pulsePoint {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

.mode-nav {
  display: flex;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 4px;
}
.mtab {
  flex: 1;
  padding: 0.5rem 0.6rem;
  border-radius: 50px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-mid);
  transition:
    background 0.25s var(--ease-smooth),
    color 0.25s;
  letter-spacing: 0.01em;
}
.mtab:hover {
  color: var(--text-hi);
}
.mtab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.timer-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 2rem 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.35);
}
.timer-card::before {
  content: "";
  position: absolute;
  top: 25%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.045;
  filter: blur(70px);
  pointer-events: none;
  transition:
    background 0.4s,
    opacity 0.4s;
}
body.is-running .timer-card::before {
  opacity: 0.1;
  animation: ambientPulse 4s ease-in-out infinite;
}
@keyframes ambientPulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.35);
  }
}

.ring-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 11;
}
.ring-fill {
  fill: none;
  stroke: url(#ring-grad);
  stroke-width: 11;
  stroke-linecap: round;
  transition:
    stroke-dashoffset 0.6s linear,
    stroke 0.4s;
}
.ring-glow {
  fill: none;
  stroke: var(--accent);
  stroke-width: 11;
  stroke-linecap: round;
  opacity: 0.4;
  transition:
    stroke-dashoffset 0.6s linear,
    stroke 0.4s;
  filter: url(#f-glow);
}

.timer-face {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}
.digits-row {
  display: flex;
  align-items: center;
}
.digit {
  font-family: var(--f-mono);
  font-size: 3rem;
  font-weight: 600;
  color: var(--text-hi);
  letter-spacing: -0.03em;
  line-height: 1;
  width: 2.3ch;
  text-align: center;
}
.digit-sep {
  font-family: var(--f-mono);
  font-size: 2.6rem;
  color: var(--text-lo);
  animation: colonBlink 1s step-start infinite;
  line-height: 1;
  padding: 0 0.04rem;
  margin-bottom: 0.05rem;
}
@keyframes colonBlink {
  50% {
    opacity: 0;
  }
}

.mode-sublabel {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--accent);
  text-transform: uppercase;
  opacity: 0.8;
  transition: color 0.4s;
}

.btn-main {
  width: 180px;
  padding: 0.8rem 0;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: #fff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  transition:
    transform 0.2s var(--ease-bounce),
    box-shadow 0.2s,
    background 0.3s,
    filter 0.2s;
}
.btn-main:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  filter: brightness(1.08);
}
.btn-main:active {
  transform: scale(0.96);
}
.btn-main.is-stop {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #ef4444;
  box-shadow: 0 2px 12px rgba(239, 68, 68, 0.12);
}
.btn-main.is-stop:hover {
  background: rgba(239, 68, 68, 0.2);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.28);
}

.adj-strip {
  display: flex;
  gap: 0.6rem;
}
.adj-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.9rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 50px;
  font-size: 0.78rem;
  color: var(--text-mid);
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s,
    transform 0.15s;
}
.adj-btn svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.adj-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-hover);
  color: var(--text-hi);
  transform: translateY(-1px);
}
.adj-btn:active {
  transform: scale(0.97);
}
.adj-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.chart-panel,
.history-panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 1.4rem 1.4rem 1.15rem;
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.3);
}

.chart-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
  gap: 0.65rem;
}
.chart-heading {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-hi);
}
.chart-subheading {
  font-size: 0.72rem;
  color: var(--text-lo);
  margin-top: 2px;
}

.chart-legend {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}
.lgd {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-mid);
}
.lgd-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.lgd-focus {
  background: #ef4444;
}
.lgd-short {
  background: #14b8a6;
}
.lgd-long {
  background: #8b5cf6;
}

.chart-canvas-wrap {
  position: relative;
  height: 155px;
}

.chart-stats {
  display: flex;
  gap: 1px;
  margin-top: 0.9rem;
  background: var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.stat-box {
  flex: 1;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.55rem 0.25rem;
  gap: 2px;
}
.stat-val {
  font-family: var(--f-mono);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-hi);
  line-height: 1;
}
.stat-key {
  font-size: 0.65rem;
  color: var(--text-lo);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.history-actions {
  display: flex;
  gap: 4px;
}
.history-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-lo);
  transition:
    background 0.2s,
    transform 0.3s var(--ease-smooth),
    color 0.2s;
}
.history-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.3s var(--ease-smooth);
}
.history-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-mid);
}
.history-toggle[aria-expanded="false"] svg {
  transform: rotate(-90deg);
}

.history-body {
  overflow: hidden;
  transition:
    max-height 0.35s var(--ease-smooth),
    opacity 0.25s;
  max-height: 600px;
  opacity: 1;
}
.history-body.is-collapsed {
  max-height: 0;
  opacity: 0;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem 0.9rem;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: background 0.2s;
}
.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.hist-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.hist-mode-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.18rem 0.55rem;
  border-radius: 50px;
  text-transform: uppercase;
}
.hist-mode-badge.m-pomodoro {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}
.hist-mode-badge.m-short-break {
  background: rgba(20, 184, 166, 0.15);
  color: #2dd4bf;
}
.hist-mode-badge.m-long-break {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
}

.hist-time {
  font-size: 0.68rem;
  color: var(--text-lo);
  margin-left: auto;
  letter-spacing: 0.03em;
}
.hist-rating {
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
}
.hist-rating svg {
  width: 1.25rem;
  height: 1.25rem;
}

.hist-note {
  font-size: 0.82rem;
  color: var(--text-mid);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-empty {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-lo);
  padding: 1.25rem 0;
  line-height: 1.6;
}

.app-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-lo);
  padding-top: 0.15rem;
}
.app-footer em {
  font-style: normal;
  color: var(--accent);
  transition: color 0.4s;
}
kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 0 5px;
  font-family: var(--f-mono);
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-mid);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: fadeIn 0.3s var(--ease-smooth) both;
}
.modal-card {
  background: var(--surface-1);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--r-xl);
  width: min(96vw, 460px);
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.65);
  animation: cardUp 0.4s var(--ease-bounce) both;
}

.modal-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16/6;
  background: #0e0e14;
  overflow: hidden;
}
.modal-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.modal-img-wrap.no-img .modal-photo {
  display: none;
}
.modal-img-wrap.no-img .pcard-img-fallback {
  display: flex;
}
.modal-fallback {
  position: absolute;
  inset: 0;
}
.modal-img-badge {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.28rem 0.75rem;
  border-radius: 50px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.modal-inner {
  padding: 1.4rem 1.6rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.modal-q {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-hi);
  line-height: 1.3;
}

.emoji-row {
  display: flex;
  gap: 0.55rem;
}
.em-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 2.5px solid transparent;
  background: none;
  transition:
    transform 0.22s var(--ease-bounce),
    border-color 0.2s,
    box-shadow 0.2s;
}
.em-btn svg {
  width: 40px;
  height: 40px;
  display: block;
  border-radius: 50%;
}
.em-btn:hover {
  transform: scale(1.2);
}
.em-btn.picked {
  border-color: var(--accent);
  transform: scale(1.12);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.journal-ta {
  width: 100%;
  resize: vertical;
  min-height: 78px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.7rem 0.85rem;
  font-family: var(--f-ui);
  font-size: 0.875rem;
  color: var(--text-hi);
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.55;
}
.journal-ta::placeholder {
  color: var(--text-lo);
}
.journal-ta:focus {
  border-color: var(--accent);
}

.char-count {
  display: block;
  text-align: right;
  font-size: 0.68rem;
  color: var(--text-lo);
  margin-top: -0.45rem;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}
.mbtn {
  padding: 0.62rem 1.35rem;
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition:
    background 0.2s,
    transform 0.15s var(--ease-bounce),
    box-shadow 0.2s;
}
.mbtn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-mid);
}
.mbtn-ghost:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-hi);
}
.mbtn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
}
.mbtn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  filter: brightness(1.08);
}
.mbtn-primary:active {
  transform: scale(0.97);
}

@media (max-width: 420px) {
  .digit {
    font-size: 2.5rem;
    width: 2.1ch;
  }
  .digit-sep {
    font-size: 2.1rem;
  }
  .ring-wrap {
    width: 188px;
    height: 188px;
  }
  .pcard-heading {
    font-size: 1.4rem;
  }
  .chart-canvas-wrap {
    height: 120px;
  }
  .btn-main {
    width: 155px;
  }
}
