
.tm-body {
  min-height: 100vh;
  min-height: 100dvh;
}

.tm {
  --tm-size: clamp(56px, min(21vw, 30vh), 260px);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 max(var(--pad), env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
}

.tm-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px 20px;
  padding: max(18px, env(safe-area-inset-top)) 0 18px;
}

.tm-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  line-height: 1;
}

.tm-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}

.tm-mode {
  position: relative;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  color: var(--ink-2);
  white-space: nowrap;
  transition: background .2s var(--ease), color .2s var(--ease);
}

.tm-mode[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.tm-mode.is-live::after,
.tm-mode.is-done::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--forest-2);
}

.tm-mode.is-done::after { background: #7A2E2E; }

.tm-stage {
  width: 100%;
  max-width: 880px;
  margin: clamp(20px, 10vh, 130px) auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.tm-status,
.tm-sub,
.tm-hint {
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--muted);
}

.tm-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 12px;
}

.tm-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transition: background .2s var(--ease);
}

.tm[data-state="running"] .tm-status::before {
  background: var(--forest-2);
  animation: tm-blink 1.6s ease-in-out infinite;
}

.tm[data-state="finished"] .tm-status { color: var(--forest); }
.tm[data-state="finished"] .tm-status::before { background: var(--forest); }

@keyframes tm-blink {
  50% { opacity: 0.25; }
}

.tm-time {
  margin-top: clamp(14px, 3vh, 28px);
  font-family: var(--f-mono);
  font-size: var(--tm-size);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink);
  transition: color .25s var(--ease);
}

.tm.is-long { --tm-size: clamp(44px, min(15vw, 30vh), 220px); }

@supports (height: 1dvh) {
  .tm { --tm-size: clamp(56px, min(21vw, 30dvh), 260px); }
  .tm.is-long { --tm-size: clamp(44px, min(15vw, 30dvh), 220px); }
}

.tm-time__frac {
  font-size: 0.4em;
  letter-spacing: -0.02em;
  color: var(--muted);
}

.tm:not([data-mode="stopwatch"]) .tm-time__frac { display: none; }

.tm[data-tone="read"] .tm-time { color: var(--forest); }
.tm[data-tone="over"] .tm-time { color: #7A2E2E; }

.tm[data-state="paused"] .tm-time { color: var(--muted); }
.tm[data-state="finished"] .tm-time { color: var(--forest); animation: tm-pulse 1.2s ease-in-out 3; }

@keyframes tm-pulse {
  50% { opacity: 0.35; }
}

.tm-progress {
  width: min(100%, 520px);
  height: 4px;
  margin-top: clamp(18px, 3.5vh, 32px);
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.tm-progress__fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--forest);
  transform-origin: left center;
  transform: scaleX(0);
}

.tm-sub {
  margin-top: 14px;
  min-height: 12px;
}

.tm-sub.is-over { color: #7A2E2E; }

.tm[data-mode="interview"] .tm-sub {
  min-height: 20px;
  font-size: clamp(15px, 2.2vw, 20px);
  color: var(--ink-2);
}

.tm[data-mode="interview"] .tm-sub.is-over { color: #7A2E2E; }

.tm[data-mode="stopwatch"] .tm-progress,
.tm[data-mode="stopwatch"] .tm-sub { visibility: hidden; }

.tm-controls {
  width: min(100%, 520px);
  margin-top: clamp(22px, 4vh, 40px);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 10px;
}

.tm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
  touch-action: manipulation;
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease), opacity .2s var(--ease);
}

.tm-btn--primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.tm-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.tm[data-mode="countdown"] #tm-next { display: none; }

.tm-mode:focus-visible,
.tm-btn:focus-visible,
.tm-chip:focus-visible,
.tm-brand:focus-visible {
  outline: 2px solid var(--forest);
  outline-offset: 3px;
}

.tm-panel {
  width: 100%;
  max-width: 520px;
  margin: clamp(24px, 4.5vh, 44px) auto 0;
}

.tm-stage,
.tm-panel {
  transition: opacity .36s var(--ease), transform .36s var(--ease);
}

.tm-panel { transition-delay: .07s; }

.tm.is-switching .tm-stage,
.tm.is-switching .tm-panel,
.tm.is-reformat .tm-panel {
  opacity: 0;
  transform: translateY(10px);
  transition-duration: .16s;
  transition-delay: 0s;
}

.tm-setup,
.tm-rows,
.tm-log { display: none; }

.tm[data-mode="countdown"] .tm-setup--countdown,
.tm[data-mode="interview"][data-setup="open"] .tm-setup--interview { display: grid; }

.tm[data-format="panel"] .tm-rows[data-for="panel"],
.tm[data-format="mmi"] .tm-rows[data-for="mmi"] { display: grid; }

.tm[data-mode="stopwatch"] .tm-log,
.tm[data-mode="interview"][data-setup="closed"] .tm-log { display: grid; }

.tm-setup {
  gap: 16px;
  justify-items: center;
}

.tm-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

@media (min-width: 680px) {
  .tm-setup--countdown .tm-chips {
    flex-wrap: nowrap;
    margin: 0 -60px;
  }
}

.tm-chip {
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  color: var(--ink-2);
  touch-action: manipulation;
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease), opacity .2s var(--ease);
}

.tm-chip[aria-pressed="true"] {
  border-color: var(--forest);
  background: var(--forest);
  color: #fff;
}

.tm-chip:disabled { opacity: 0.45; cursor: default; }

.tm-rows {
  width: 100%;
  border-top: 1px solid var(--line);
}

.tm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}

.tm-row__label {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  text-align: left;
}

.tm-inputs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.tm-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--muted);
}

.tm-field input {
  width: 60px;
  padding: 11px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-family: var(--f-mono);
  font-size: 17px;
  font-weight: 500;
  line-height: 1;
  text-align: center;
  color: var(--ink);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), opacity .2s var(--ease);
}

.tm-field input:focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(42, 74, 58, 0.14);
}

.tm-field input:disabled { opacity: 0.45; }

.tm-log {
  list-style: none;
  border-top: 1px solid var(--line);
}

.tm-log:empty { border-top: 0; }

.tm-lap {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 18px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line);
  font-family: var(--f-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.tm-lap__idx { text-align: left; color: var(--muted); }
.tm-lap__split { color: var(--ink); }
.tm-lap__total { min-width: 10ch; text-align: right; color: var(--muted); }
.tm-lap.is-over .tm-lap__split { color: #7A2E2E; }

.tm-hint {
  display: none;
  margin-top: auto;
  padding-top: 32px;
  text-align: center;
  font-size: 11px;
}

@media (hover: hover) and (pointer: fine) {
  .tm-hint { display: block; }
}

.tm-noscript {
  padding: 0 var(--pad) 32px;
  text-align: center;
  color: var(--muted);
}

@media (hover: hover) {
  .tm-mode:not([aria-pressed="true"]):hover { color: var(--ink); }
  .tm-btn:hover:not(:disabled) { border-color: var(--ink); }
  .tm-chip:hover:not(:disabled) { border-color: var(--forest); color: var(--forest); }
  .tm-chip[aria-pressed="true"]:hover:not(:disabled) { border-color: var(--forest); color: #fff; }
  .tm-btn--primary:hover:not(:disabled) { border-color: var(--forest); background: var(--forest); color: #fff; }
}

@media (max-width: 520px) {
  .tm-top { justify-content: center; }
  .tm-modes { flex: 1 0 100%; }
  .tm-mode { padding: 12px 6px; text-align: center; }
  .tm-btn { padding: 0 10px; }
  .tm-inputs { gap: 10px; }
  .tm-field { gap: 6px; letter-spacing: 0.08em; }
  .tm-field input { width: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .tm-stage, .tm-panel { transition: none; }
  .tm[data-state="running"] .tm-status::before,
  .tm[data-state="finished"] .tm-time { animation: none; }
}
