/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Takshashila brand palette — sampled from logo */
  --brand:        #610d3d;   /* lighthouse tower — deep plum */
  --brand-dark:   #440a2b;   /* hover / pressed */
  --brand-mid:    #8c1257;   /* medium tint for accents */
  --brand-light:  #f9eef5;   /* tinted background */
  --amber:        #f5a623;   /* sun halo */
  --yellow:       #ffd600;   /* sun centre */
  --amber-light:  #fef3dc;   /* amber tint */

  --text:         #1a1a1a;
  --muted:        #5a5a5a;
  --border:       #e0d4db;
  --bg:           #f7f3f5;   /* very light plum tint */
  --card-bg:      #ffffff;
  --success:      #1a6e35;
  --error:        #b91c1c;
  --radius:       8px;
  --shadow:       0 1px 4px rgba(97,13,61,.07), 0 2px 12px rgba(97,13,61,.06);
  --font:         'Georgia', serif;
  --mono:         'Menlo', 'Consolas', monospace;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--brand);
  color: #fff;
  padding: 0;
  border-bottom: 4px solid var(--amber);
}
.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 1.3rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
}
.header-logo {
  height: 52px;
  width: auto;
  flex-shrink: 0;
  filter: brightness(0) invert(1);  /* white version */
}
.header-text { flex: 1; }
.logo-row {
  display: flex;
  align-items: baseline;
  gap: .55rem;
  font-size: 1.05rem;
  font-weight: bold;
  letter-spacing: .02em;
  margin-bottom: .2rem;
}
.logo-divider { opacity: .45; }
.tool-name {
  font-weight: normal;
  opacity: .88;
  color: var(--amber);
}
.header-sub { font-size: .88rem; opacity: .8; font-style: italic; }

/* ── Amber accent bar ─────────────────────────────────────────────────────── */
.accent-bar {
  height: 3px;
  background: linear-gradient(90deg, var(--yellow), var(--amber));
  border-radius: 0 0 3px 3px;
}

/* ── Main / layout ────────────────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 2rem auto 3rem;
  padding: 0 1.5rem;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem 1.8rem;
  margin-bottom: 1.4rem;
}
.card h2 {
  font-size: 1.05rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1rem;
  color: var(--brand);
}
.card-desc {
  font-size: .88rem;
  color: var(--muted);
  margin-top: -.5rem;
  margin-bottom: 1rem;
}

/* Step badge */
.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  font-size: .76rem;
  font-family: sans-serif;
  font-weight: bold;
  flex-shrink: 0;
}

/* ── Tip box ──────────────────────────────────────────────────────────────── */
.tip {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  background: var(--amber-light);
  border-left: 3px solid var(--amber);
  border-radius: 4px;
  padding: .7rem .9rem;
  font-size: .88rem;
  color: #5a3a00;
  margin-bottom: 1rem;
}
.tip svg { flex-shrink: 0; margin-top: 2px; color: var(--amber); }
.tip a { color: var(--brand); }

/* ── Token row ────────────────────────────────────────────────────────────── */
.token-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .3rem;
}
.token-row input {
  flex: 1;
  font-family: var(--mono);
  font-size: .88rem;
}
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .42rem .5rem;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  transition: color .15s, border-color .15s;
}
.btn-icon:hover { color: var(--brand); border-color: var(--brand); }
.btn-sm { padding: .42rem .9rem; font-size: .85rem; }
.btn-danger { color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: #fee2e2; }

/* ── Form fields ──────────────────────────────────────────────────────────── */
label {
  display: block;
  font-size: .88rem;
  font-weight: bold;
  margin-bottom: .3rem;
  color: var(--text);
}
.hint {
  font-weight: normal;
  color: var(--muted);
  font-size: .82rem;
}
.req { color: var(--brand); }

input[type="text"],
input[type="url"],
input[type="date"],
input[type="password"],
textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: var(--font);
  font-size: .95rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(97,13,61,.12);
}
input.error, textarea.error {
  border-color: var(--error);
}
textarea { resize: vertical; }

.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }
.field-hint {
  font-size: .8rem;
  color: var(--muted);
  margin-top: .3rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.2rem;
}
.field-grid .field.full { grid-column: 1 / -1; }

.filename-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.filename-row input { flex: 1; }
.filename-ext {
  font-size: .88rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: var(--mono);
}

/* ── Aside guide card ─────────────────────────────────────────────────────── */
.aside-guide {
  background: #fdfcfb;
  border-color: #ddd;
}
.aside-guide h2 {
  font-size: .95rem;
  color: var(--muted);
}
.aside-guide p { font-size: .88rem; margin-bottom: .6rem; }
.aside-guide pre {
  background: #f5f0ec;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: .7rem 1rem;
  font-family: var(--mono);
  font-size: .82rem;
  margin-bottom: .6rem;
  overflow-x: auto;
}
code {
  font-family: var(--mono);
  font-size: .88em;
  background: #f5f0ec;
  padding: .1em .35em;
  border-radius: 3px;
}
.aside-guide pre code { background: none; padding: 0; }

/* ── How it works collapsible ────────────────────────────────────────────── */
.how-it-works {
  background: #fdfcfb;
  border-color: #ddd;
  padding: 0;            /* summary provides its own padding */
}
.how-it-works summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1.1rem 1.5rem;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
  border-radius: var(--radius);
  user-select: none;
}
.how-it-works summary::-webkit-details-marker { display: none; }
.how-it-works summary::after {
  content: "▸";
  margin-left: auto;
  font-size: .8rem;
  color: var(--muted);
  transition: transform .2s;
}
.how-it-works[open] summary::after { transform: rotate(90deg); }
.how-it-works summary:hover { color: var(--brand); }
.how-icon { font-size: 1.1rem; }

.how-body {
  padding: 0 1.5rem 1.4rem;
  border-top: 1px solid var(--border);
}
.how-body h3 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--brand);
  margin: 1.2rem 0 .55rem;
  font-family: var(--font);
}
.how-body ol, .how-body ul {
  padding-left: 1.4rem;
  font-size: .88rem;
  color: var(--text);
  line-height: 1.7;
}
.how-body li { margin-bottom: .3rem; }
.how-body ul { margin-top: .3rem; }

.paper-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  background: var(--brand-light);
  color: var(--brand);
  border-radius: 10px;
  padding: .1em .5em;
  vertical-align: middle;
  margin-left: .3rem;
}

/* Conventions table */
.conventions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  margin-top: .6rem;
}
.conventions-table th {
  background: var(--brand-light);
  color: var(--brand);
  font-weight: 700;
  text-align: left;
  padding: .5rem .75rem;
  border-bottom: 2px solid var(--border);
}
.conventions-table td {
  padding: .45rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.conventions-table tr:last-child td { border-bottom: none; }
.conventions-table tr:nth-child(even) td { background: #faf8fb; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.submit-row {
  display: flex;
  justify-content: flex-end;
  margin-top: .5rem;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: .7rem 1.8rem;
  font-size: 1rem;
  font-family: var(--font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: var(--brand);
  border: 1.5px solid var(--brand);
  border-radius: 5px;
  padding: .6rem 1.4rem;
  font-size: .95rem;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--brand-light); }

.btn-text {
  background: none;
  border: none;
  color: var(--brand);
  font-family: var(--font);
  font-size: .9rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  margin-top: .8rem;
  display: inline-block;
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner:not([hidden]) {
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress area ────────────────────────────────────────────────────────── */
#progressArea { margin-top: 1.4rem; }

.progress-card { padding: 1.8rem 2rem; }

.progress-steps {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  margin-bottom: 1.2rem;
}
.prog-step {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .95rem;
  color: var(--muted);
}
.prog-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ddd;
  flex-shrink: 0;
  transition: background .3s;
}
.prog-step.done   .prog-dot { background: var(--success); }
.prog-step.active .prog-dot { background: var(--amber); animation: pulse 1s ease-in-out infinite; }
.prog-step.done   .prog-label { color: var(--success); font-weight: bold; }
.prog-step.active .prog-label { color: var(--text); font-weight: bold; }

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

.progress-msg {
  font-size: .88rem;
  color: var(--muted);
  font-style: italic;
  min-height: 1.4em;
}

/* ── Result area ──────────────────────────────────────────────────────────── */
#resultArea { margin-top: 1.4rem; }

.result-card {
  text-align: center;
  padding: 2.5rem 2rem;
}
.result-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  font-size: 1.4rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}
.success-icon { background: #d1fae5; color: var(--success); }
.error-icon   { background: #fee2e2; color: var(--error); }

.result-card h2 {
  justify-content: center;
  margin-bottom: .5rem;
  color: var(--text);
}
.result-card p { font-size: .95rem; color: var(--muted); margin-bottom: 1.4rem; }
.error-text { color: var(--error) !important; font-size: .9rem !important; }

.download-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  justify-content: center;
  margin-bottom: 1rem;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1rem;
  font-size: .82rem;
  color: var(--muted);
  border-top: 3px solid var(--brand);
  background: #fff;
}
footer a { color: var(--brand); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Paper / Blog toggle ──────────────────────────────────────────────────── */
.doctype-toggle {
  display: flex;
  gap: 1rem;
  margin-bottom: .2rem;
}
.doctype-option {
  position: relative;
  flex: 1;
}
.doctype-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.doctype-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  padding: .85rem .6rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  font-size: .88rem;
  color: var(--muted);
  background: #fafafa;
  transition: border-color .15s, background .15s, color .15s;
  user-select: none;
}
.doctype-btn .toggle-icon { font-size: 1.5rem; }
.doctype-btn .toggle-label { font-weight: 600; }
.doctype-btn .toggle-sub   { font-size: .78rem; }
.doctype-option input[type="radio"]:checked + .doctype-btn {
  border-color: var(--brand);
  background: #fdf0f7;
  color: var(--brand);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: .6rem; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .field.full { grid-column: 1; }
  .download-buttons { flex-direction: column; align-items: center; }
  .card { padding: 1.2rem 1.1rem; }
  .token-row { flex-wrap: wrap; }
  .token-row input { width: 100%; }
}
