:root {
  --bg: #0d0b07;
  --bg-elev: #17130c;
  --bg-card: #1e1810;
  --line: #3a2f1d;
  --gold: #c9a227;
  --gold-bright: #e8c75a;
  --text: #e9e1cf;
  --text-dim: #9a8f76;
  --green: #6fae5f;
  --red: #c0563f;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --tap: 48px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ---------------- Login ---------------- */
.login {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(
      ellipse at top,
      rgba(201, 162, 39, 0.12),
      transparent 60%
    ),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.crest {
  font-size: 30px;
  letter-spacing: 6px;
  margin: 0;
  color: var(--gold-bright);
  font-weight: 700;
  text-shadow: 0 0 18px rgba(201, 162, 39, 0.4);
}

.subtitle {
  color: var(--text-dim);
  letter-spacing: 1px;
  margin: 8px 0 28px;
  font-size: 14px;
  text-transform: uppercase;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

input[type="password"] {
  width: 100%;
  height: var(--tap);
  padding: 0 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  outline: none;
}

input[type="password"]:focus {
  border-color: var(--gold);
}

button {
  cursor: pointer;
  font-family: inherit;
}

#login-btn {
  height: var(--tap);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #2a2110, #1a1409);
  color: var(--gold-bright);
  font-size: 16px;
  letter-spacing: 0.5px;
  transition: filter 0.15s;
}

#login-btn:active {
  filter: brightness(1.3);
}

.error {
  color: var(--red);
  min-height: 18px;
  margin: 4px 0 0;
  font-size: 14px;
}

/* ---------------- App header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px;
  box-shadow: var(--shadow);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title {
  font-size: 19px;
  margin: 0;
  color: var(--gold-bright);
  letter-spacing: 1px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  min-height: 36px;
}

.ghost-btn.danger {
  color: var(--red);
  border-color: #543026;
}

.overall {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.progress-track {
  flex: 1;
  height: 10px;
  background: #0a0805;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width 0.35s ease;
}

.progress-label {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--gold-bright);
  min-width: 64px;
  text-align: right;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
  user-select: none;
}

.switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

/* ---------------- Episodes ---------------- */
.episodes {
  padding: 12px 12px 40px;
  max-width: 720px;
  margin: 0 auto;
}

.episode {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.episode-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 14px 14px;
  min-height: var(--tap);
}

.episode-header .chevron {
  color: var(--gold);
  transition: transform 0.2s;
  font-size: 13px;
}

.episode.collapsed .chevron {
  transform: rotate(-90deg);
}

.episode-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--gold-bright);
}

.episode-count {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.episode-bar {
  height: 4px;
  background: #0a0805;
}

.episode-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 0.3s;
}

.episode-note {
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
  padding: 0 14px 6px;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 4px 0 8px;
}

.episode.collapsed .steps,
.episode.collapsed .episode-note {
  display: none;
}

/* ---------------- Step ---------------- */
.step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid rgba(58, 47, 29, 0.45);
  transition: opacity 0.2s;
}

.step:first-child {
  border-top: none;
}

.step.checked {
  opacity: 0.55;
}

.step.checked .step-label {
  text-decoration: line-through;
  text-decoration-color: var(--text-dim);
}

/* When "show completed" is off, hide checked steps — but always keep the most
   recently checked one visible so you can review or undo it. */
body:not(.show-completed) .step.checked:not(.last-checked) {
  display: none;
}

/* Checkbox is a button with a big invisible tap area around a 26px visual box. */
.checkbox {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  padding: 0;
  margin: -8px 0 -8px -6px;
  padding: 8px 8px 8px 6px;
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  touch-action: manipulation;
}

.checkbox-box {
  width: 28px;
  height: 28px;
  margin-top: 1px;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.checkbox:active .checkbox-box {
  border-color: var(--gold);
}

.step.checked .checkbox-box {
  border-color: var(--green);
  background: var(--green);
}

.checkbox-box svg {
  width: 17px;
  height: 17px;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.12s, transform 0.12s;
}

.step.checked .checkbox-box svg {
  opacity: 1;
  transform: scale(1);
}

/* Always-visible "where to find it" line. */
.step-detail {
  margin-top: 3px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.4;
}

.step.checked .step-detail {
  text-decoration: line-through;
  text-decoration-color: rgba(154, 143, 118, 0.5);
}

/* "Last done" marker — the one checked item kept on screen. */
.last-badge {
  display: none;
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--gold-bright);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

.step.last-checked {
  background: rgba(201, 162, 39, 0.07);
  opacity: 0.8;
}

.step.last-checked .last-badge {
  display: inline-block;
}

.step-body {
  flex: 1;
  min-width: 0;
}

.step-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.type-icon {
  flex: 0 0 auto;
  font-size: 15px;
  line-height: 1.3;
  width: 1.4em;
  text-align: center;
}

.step-label {
  flex: 1;
  font-size: 16px;
}

.step.type-item .step-label {
  color: var(--text);
}

.step.type-grace .step-label,
.step.type-boss .step-label,
.step.type-achievement .step-label {
  font-weight: 600;
}

.step.type-grace .step-label {
  color: var(--gold-bright);
}

.step.type-boss .step-label {
  color: #d98a6a;
}

.step.type-npc .step-label {
  color: #c8b7e0;
}

.step.type-achievement .step-label {
  color: var(--gold-bright);
}

.note-toggle {
  margin-top: 4px;
  background: transparent;
  border: none;
  color: var(--gold);
  font-size: 12.5px;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.note {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.25);
  border-left: 2px solid var(--line);
  border-radius: 0 6px 6px 0;
  padding: 8px 10px;
  line-height: 1.45;
}

.note.hidden {
  display: none;
}

/* All-done state for an episode */
.episode-allclear {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--green);
  font-style: italic;
}

body.show-completed .episode-allclear {
  display: none;
}

/* ---------------- Footer & toast ---------------- */
.app-footer {
  text-align: center;
  color: #6a6049;
  font-size: 11px;
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 1;
  transition: opacity 0.3s;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}
