:root {
  --bg: #14151a;
  --fg: #e8e6df;
  --muted: #8a8a94;
  --accent: #d9b44a;
  --danger: #d8483f;
  --good: #4caf7d;
  --panel: #1d1f27;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: Georgia, "Times New Roman", serif;
}

/* ---------- screen switching ---------- */
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ---------- setup screen ---------- */
#setup.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.setup-inner {
  max-width: 34rem;
  width: 100%;
  text-align: center;
}

h1 {
  font-size: 3.5rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--accent);
  font-style: italic;
  margin: 0.25rem 0 1.5rem;
  font-size: 1.2rem;
}

.rules {
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.95rem;
  margin-bottom: 2rem;
}
.rules strong { color: var(--fg); }

.mode-toggle {
  display: inline-flex;
  border: 1px solid #333;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.mode-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.5rem 1.5rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
}
.mode-btn.active { background: var(--accent); color: #14151a; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1.2rem;
}
.preset-btn {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, background 0.15s;
}
.preset-btn:hover { border-color: var(--accent); }
.preset-btn.active { border-color: var(--accent); background: #2a2620; }

.custom-row {
  color: var(--muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}
.custom-row input {
  width: 6rem;
  background: var(--panel);
  border: 1px solid #333;
  border-radius: 6px;
  color: var(--fg);
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  font-size: 1rem;
}

.start-btn {
  background: var(--accent);
  color: #14151a;
  border: none;
  border-radius: 8px;
  padding: 0.85rem 2.2rem;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}
.start-btn:hover { filter: brightness(1.08); }
.start-btn.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid #444;
}

.hint { color: var(--danger); min-height: 1.2rem; margin-top: 0.9rem; }

/* ---------- writing screen ---------- */
#writing.active {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
  border-bottom: 1px solid #24252d;
  font-family: -apple-system, system-ui, sans-serif;
}
.goal-progress {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  min-width: 8rem;
}

.grace-track {
  flex: 1;
  height: 6px;
  background: #24252d;
  border-radius: 999px;
  overflow: hidden;
}
.grace-meter {
  height: 100%;
  width: 100%;
  background: var(--good);
  transition: background 0.1s linear;
}

#editor {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  resize: none;
  font-family: Georgia, serif;
  font-size: 1.25rem;
  line-height: 1.8;
  transition: opacity 0.12s linear;
}
#editor::placeholder { color: #4a4b54; }

/* ---------- overlays ---------- */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.9);
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.active { display: flex; }

.overlay-card {
  background: var(--panel);
  border: 1px solid #333;
  border-radius: 14px;
  padding: 2.5rem 3rem;
  text-align: center;
  max-width: 30rem;
}
.overlay-card.fail { border-color: var(--danger); }
.overlay-card h2 { margin: 0 0 0.5rem; font-size: 2rem; }
.overlay-card.fail h2 { color: var(--danger); }
.overlay-sub { color: var(--muted); margin-bottom: 1.8rem; }

.overlay-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}
.link-btn:hover { color: var(--fg); }
