:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #607080;
  --line: #d9e0e7;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --ok: #16803c;
  --warn: #b7791f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.backup-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.status-band,
.control-panel,
.readout,
.system-state,
.history-section,
.log-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.status-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 2.5vw, 2.25rem);
}

h2 {
  font-size: 1.05rem;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #8c99a6;
}

.dot.connected {
  background: var(--ok);
}

.dot.error {
  background: var(--danger);
}

.control-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding: 14px;
}

.mode-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-panel button {
  min-width: 0;
}

.mode-panel button,
.mode-panel .backup-link {
  width: 100%;
  padding: 0 8px;
  font-size: 0.9rem;
}

.toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toggle.is-disabled {
  opacity: 0.55;
}

.manual-panel {
  display: grid;
  grid-template-columns: minmax(240px, 0.55fr) minmax(260px, 1fr);
  gap: 14px;
  align-items: stretch;
  margin-top: 14px;
}

.manual-timer-button,
.manual-stats {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.manual-timer-button {
  min-height: 148px;
  padding: 16px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 1.45rem;
  font-weight: 900;
}

.manual-timer-button.is-running {
  border-color: var(--danger);
  background: var(--danger);
}

.manual-stats {
  padding: 20px;
}

.manual-stats strong {
  display: block;
  margin: 4px 0 8px;
  font-size: clamp(3rem, 8vw, 5.6rem);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.manual-stats span:last-child {
  color: var(--muted);
  font-weight: 700;
}

.readout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 14px;
  margin-top: 14px;
}

.readout {
  padding: 24px;
}

.label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

#latestTime {
  display: block;
  margin: 4px 0 8px;
  font-size: clamp(4rem, 11vw, 8rem);
  line-height: 0.95;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

#latestMeta {
  color: var(--muted);
  font-weight: 700;
}

.system-state {
  display: grid;
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.system-state > div {
  min-height: 96px;
  padding: 18px;
  background: #fff;
}

.system-state strong {
  font-size: 1.8rem;
  font-variant-numeric: tabular-nums;
}

.history-section,
.log-section {
  margin-top: 14px;
  padding: 16px;
}

.history-section header,
.log-section header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 74px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-list .time {
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.history-list .date {
  color: var(--muted);
  font-size: 0.9rem;
}

#logOutput {
  min-height: 86px;
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #d7fbe8;
  font-size: 0.88rem;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 10px;
  }

  .status-band,
  .readout-grid {
    display: block;
  }

  .connection {
    margin-top: 12px;
  }

  .system-state {
    margin-top: 14px;
  }

  .control-panel button,
  .backup-link,
  .toggle {
    width: 100%;
    justify-content: center;
  }

  .mode-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .manual-panel {
    grid-template-columns: 1fr;
  }

  .history-list li {
    grid-template-columns: 58px 1fr;
  }

  .history-list .date {
    grid-column: 1 / -1;
  }
}
