*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 20px;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.status-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-badge,
.phase-badge {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.status-unknown { color: var(--text-muted); }
.status-ok { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.phase-badge {
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

/* Phase guide */
.phase-guide {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.phase-guide p {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.6;
}

.phase-guide-ready {
  border: 2px solid var(--accent);
  background: rgba(245, 158, 11, 0.12);
}

.phase-guide-ready p {
  color: var(--accent);
  font-weight: 600;
}

/* Progress */
.progress-section {
  text-align: center;
  margin-bottom: 20px;
}

.countdown-ring {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 12px;
}

.countdown-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 283;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s linear;
}

.countdown-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.live-db {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:not(:disabled):active {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:not(:disabled):active {
  background: var(--border);
}

.btn-accent {
  background: var(--accent);
  color: #1a1200;
}

.btn-accent:not(:disabled):active {
  background: var(--accent-hover);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:not(:disabled):active {
  background: rgba(239, 68, 68, 0.1);
}

/* Result cards */
.result-card {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.result-card h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 500;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.rt60-grid {
  grid-template-columns: repeat(2, 1fr);
}

.result-item {
  text-align: center;
  padding: 8px 4px;
  background: var(--bg);
  border-radius: 6px;
}

.result-item.highlight {
  grid-column: span 2;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.result-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.result-value {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.result-value.invalid {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
}

/* Error */
.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 8px;
  margin-top: 8px;
}

/* Calibration */
.cal-card h2 {
  font-size: 1rem;
  font-weight: 600;
}

.cal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.cal-status {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  max-width: 55%;
}

.cal-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 12px;
}

.cal-live {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.cal-form {
  margin-bottom: 12px;
}

.cal-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.cal-form input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.cal-form input:focus {
  border-color: var(--primary);
}

.cal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  width: 100%;
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
}

.btn-danger-outline:active {
  background: rgba(239, 68, 68, 0.08);
}

/* History */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.history-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.history-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

.history-item {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px 14px;
  position: relative;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.history-room {
  font-weight: 600;
  font-size: 0.95rem;
}

.history-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-details {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.history-details strong {
  color: var(--text);
  font-weight: 500;
}

.btn-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-delete:active {
  background: rgba(239, 68, 68, 0.1);
}

/* Footer */
.footer {
  text-align: center;
  padding: 8px 0;
}

.footer p {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Utility */
.hidden {
  display: none !important;
}
