:root {
  --bg: #e8e1d6;
  --card: #fbf8f3;
  --ink: #1f1a17;
  --muted: #6f675f;
  --line: #ddd4c8;
  --yellow: #f0c14b;
  --yellow-ink: #6d4c09;
  --red: #c4312a;
  --red-ink: #8d221c;
  --calm: #2f6d4f;
  --shadow: 0 1px 0 rgba(60, 42, 24, 0.04);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.wrap {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 22px;
}

.brand { display: flex; gap: 14px; align-items: center; }

.mark { display: grid; gap: 3px; width: 18px; flex: none; }
.mark i { display: block; height: 8px; border-radius: 2px; }
.mark i:first-child { background: var(--yellow); }
.mark i:last-child { background: var(--red); }

h1, h2, p { margin: 0; }
h1 { font-size: 28px; letter-spacing: -0.03em; font-weight: 700; }
h2 { font-size: 20px; letter-spacing: -0.02em; font-weight: 650; }
.sub { color: var(--muted); margin-top: 2px; }
.sync { color: var(--muted); margin-top: 6px; font-size: 14px; }
.sync.bad { color: var(--red-ink); }

#clock { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.clock-time { display: block; color: var(--ink); font-size: 22px; font-weight: 650; letter-spacing: -0.03em; }

.banner {
  background: #fff1f0;
  color: var(--red-ink);
  border: 1px solid #f0c2bd;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid #d3c9bc;
  border-radius: 18px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 250px;
}

.card.yellow { border-top-color: #e0a106; background: #fffaf0; }
.card.red { border-top-color: var(--red); background: #fff6f5; }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.card h2 { font-size: 22px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.status.calm { color: var(--calm); font-weight: 650; letter-spacing: 0; }
.status.yellow { color: #8a5a00; }
.status.red { color: #9d1c1c; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.card.yellow .dot, .card.red .dot { animation: pulse 1.6s ease-in-out infinite; }

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

.timer-block { margin: 18px 0 8px; min-height: 78px; }
.timer {
  font-size: 40px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}
.since { color: var(--muted); margin-top: 8px; font-size: 14px; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.actions.pair { flex-direction: row; }
.actions.pair .btn { flex: 1; }

.btn {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 650;
}
.btn.yellow { background: var(--yellow); color: #2c2208; }
.btn.yellow:hover { background: #e2b23a; }
.btn.red { background: var(--red); color: #fffaf8; }
.btn.red:hover { background: #b32922; }
.btn.dark { background: var(--ink); color: #fbf8f3; }
.btn.dark:hover { background: #000; }
.btn.ghost { background: transparent; border-color: #d2c8bb; color: var(--ink); }
.btn.ghost:hover { background: rgba(40, 30, 20, 0.04); }
.btn.text {
  min-height: 36px;
  padding: 0 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 600;
}
.btn.text:hover { color: var(--ink); }
.btn.danger:hover { color: var(--red-ink); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid #d2c8bb;
  background: transparent;
}
.preset[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fbf8f3;
}
.custom-range { display: flex; align-items: center; gap: 8px; }
.custom-range input { min-height: 36px; }
.range-dash { color: var(--muted); }
.toolbar-actions { display: flex; gap: 8px; margin-left: auto; }
.toolbar-actions .btn { min-height: 36px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 18px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}
.meta { color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: #f3eee6;
  border-radius: 14px;
  padding: 14px 14px 12px;
}
.stat.yellow { background: #f8efd4; }
.stat.red { background: #f8e4e1; }
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat-label { color: var(--muted); margin-top: 2px; font-size: 14px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 10px 8px; border-bottom: 1px solid #eee4d8; text-align: left; }
th { color: var(--muted); font-size: 13px; font-weight: 650; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-bottom: none; }

.hint, .foot, .loading, .empty { color: var(--muted); }
.hint { margin-top: 12px; font-size: 13px; }
.foot { margin-top: 8px; font-size: 13px; }
.empty { padding: 8px 0 4px; }

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.log-row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 92px minmax(120px, 170px) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px 8px;
}
.log-row:hover { background: #f3eee6; }
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.pill.yellow { background: #f6e2b0; color: var(--yellow-ink); }
.pill.red { background: #f6d0cc; color: var(--red-ink); }
.log-site { font-weight: 650; }
.log-when { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-dur { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; }
.log-extra { grid-column: 2 / -1; color: var(--muted); font-size: 13px; margin-top: -4px; }
.log-note { color: var(--ink); }

#editor {
  width: min(460px, calc(100vw - 24px));
  border: none;
  border-radius: 18px;
  padding: 22px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(40, 30, 20, 0.28);
}
#editor::backdrop { background: rgba(28, 23, 19, 0.46); }
#editor h2 { margin-bottom: 4px; }
#editor form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; border: none; margin: 0; padding: 0; }
.field span, .field legend { font-size: 13px; color: var(--muted); padding: 0; }
input[type="datetime-local"], input[type="date"], select, textarea {
  width: 100%;
  border: 1px solid #d9d0c4;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 72px; resize: vertical; }
input:disabled { background: #f3eee6; color: var(--muted); }

.level-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.level-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid #d9d0c4;
  font-weight: 700;
}
.level-option input { accent-color: var(--ink); }
.level-option.yellow:has(input:checked) { background: var(--yellow); border-color: var(--yellow); color: #2c2208; }
.level-option.red:has(input:checked) { background: var(--red); border-color: var(--red); color: white; }

.check { display: flex; align-items: center; gap: 8px; }
.form-error {
  color: var(--red-ink);
  background: #fff1f0;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }

#toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  width: min(560px, calc(100vw - 24px));
}
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--ink);
  color: #fbf8f3;
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(40, 30, 20, 0.22);
}
.toast-undo {
  background: transparent;
  color: var(--yellow);
  border: none;
  font-weight: 700;
  padding: 0;
  white-space: nowrap;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

[hidden] { display: none !important; }

@media (max-width: 860px) {
  .cards, .stats { grid-template-columns: 1fr; }
  .card-top { flex-direction: column; align-items: flex-start; gap: 4px; }
  .top { flex-direction: column; align-items: flex-start; }
  #clock { text-align: left; }
  .toolbar-actions { margin-left: 0; }
  .log-row { grid-template-columns: 92px 1fr; }
  .log-when { grid-column: 2; }
  .log-dur { grid-column: 2; text-align: left; }
  .log-extra { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .card.yellow .dot, .card.red .dot { animation: none; }
}

@media print {
  body { background: white; }
  .toolbar, .actions, .foot, #toasts, .hint { display: none !important; }
  .card, .panel { break-inside: avoid; }
}
