* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0b09;
  --panel: rgba(255, 253, 248, 0.028);
  --panel-border: rgba(255, 240, 220, 0.07);
  --panel-inset: rgba(0, 0, 0, 0.35);
  --text: #f5f0e8;
  --muted: #9d9284;
  --faint: #6b6257;
  --accent: #e0743c;
  --accent-bright: #f0895a;
  --accent-soft: rgba(224, 116, 60, 0.14);
  --danger: #e05555;
  --radius: 20px;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

html, body { height: 100%; }

body {
  background:
    radial-gradient(ellipse 80% 45% at 50% -12%, rgba(224, 116, 60, 0.13), transparent 65%),
    radial-gradient(ellipse 60% 40% at 85% 110%, rgba(224, 116, 60, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

.app {
  max-width: 580px;
  margin: 0 auto;
  padding: 40px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ---------- Header ---------- */
.top { text-align: left; }

.top h1 {
  font-size: 2.7rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1;
}
.top h1 span {
  color: var(--accent);
  font-style: italic;
  text-shadow: 0 0 28px rgba(224, 116, 60, 0.45);
}
.top h1 .longform {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: normal;
  font-style: normal;
  color: var(--faint);
  letter-spacing: 0.32em;
  text-transform: uppercase;
  margin-left: 14px;
  transform: translateY(-6px);
}
.tagline {
  color: var(--muted);
  font-style: italic;
  font-size: 1.02rem;
  margin-top: 10px;
}

/* ---------- Mode chips ---------- */
.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px;
}

.mode-chip {
  flex: 0 0 auto;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.92rem;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.12s ease;
}
.mode-chip:hover { color: var(--text); transform: translateY(-1px); }
.mode-chip.active {
  background: var(--accent-soft);
  border-color: rgba(224, 116, 60, 0.55);
  color: var(--accent-bright);
  box-shadow: 0 0 20px rgba(224, 116, 60, 0.12), inset 0 0 12px rgba(224, 116, 60, 0.06);
}

/* ---------- Cards ---------- */
.stage, .result-wrap, .history-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.55);
}
.result-wrap::before {
  content: "";
  position: absolute;
  inset: 0 20% auto 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(224, 116, 60, 0.6), transparent);
}

.stage-label {
  display: block;
  color: var(--faint);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  margin-bottom: 12px;
}

.words-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.clear-text {
  border: none;
  background: none;
  color: var(--faint);
  font-family: var(--serif);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  padding: 2px 6px;
  margin-bottom: 12px;
  transition: color 0.2s ease;
}
.clear-text:hover { color: var(--accent-bright); }

/* ---------- Input ---------- */
#transcript {
  width: 100%;
  background: var(--panel-inset);
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.6;
  padding: 16px;
  resize: vertical;
  min-height: 130px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#transcript::placeholder { color: var(--faint); font-style: italic; }
#transcript:focus {
  outline: none;
  border-color: rgba(224, 116, 60, 0.5);
  box-shadow: 0 0 0 3px rgba(224, 116, 60, 0.1);
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
}
.mic { order: 1; }
.rewrite { order: 2; }
.attach { order: 3; }
#imageInput { order: 3; }
.controls .ghost { order: 4; margin-left: auto; }

.mic {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, var(--accent-bright), #c85f2c);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  box-shadow:
    0 8px 24px -6px rgba(224, 116, 60, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.mic:hover { transform: translateY(-1px); box-shadow: 0 12px 28px -6px rgba(224, 116, 60, 0.6), inset 0 1px 0 rgba(255,255,255,0.25); }
.mic:active { transform: scale(0.94); }
.mic.recording {
  background: linear-gradient(145deg, #e86a6a, #c04040);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(224, 85, 85, 0.45); }
  70% { box-shadow: 0 0 0 20px rgba(224, 85, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(224, 85, 85, 0); }
}

.rewrite {
  flex: 1 1 150px;
  min-width: 150px;
  white-space: nowrap;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #faf5ec, #e8e0d2);
  color: #171310;
  font-family: var(--serif);
  font-size: 1.06rem;
  font-weight: bold;
  letter-spacing: 0.02em;
  padding: 18px;
  cursor: pointer;
  box-shadow: 0 10px 24px -10px rgba(245, 240, 232, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: opacity 0.15s ease, transform 0.12s ease, box-shadow 0.2s ease;
}
.rewrite:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 14px 30px -10px rgba(245, 240, 232, 0.35), inset 0 1px 0 rgba(255,255,255,0.8); }
.rewrite:active:not(:disabled) { transform: translateY(0); }
.rewrite:disabled { opacity: 0.3; cursor: default; box-shadow: none; }

.ghost {
  border: none;
  background: none;
  color: var(--faint);
  font-family: var(--serif);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 8px;
  transition: color 0.2s ease;
}
.ghost:hover { color: var(--muted); }

.attach {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.12s ease;
}
.attach:hover { color: var(--accent-bright); border-color: rgba(224, 116, 60, 0.4); transform: translateY(-1px); }

.image-chip {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  margin-top: 16px;
  padding: 7px 8px 7px 7px;
  background: var(--panel-inset);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  max-width: 100%;
}
.image-chip-thumb {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  object-fit: cover;
  background: #14100c;
  flex: 0 0 auto;
  display: block;
}
.image-chip-label {
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-chip-remove {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(224, 85, 85, 0.16);
  color: var(--danger);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  margin-left: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}
.image-chip-remove:hover { background: var(--danger); color: #fff; }

.status {
  color: var(--muted);
  font-size: 0.92rem;
  font-style: italic;
  margin-top: 14px;
  min-height: 1.3em;
}
.status.error { color: var(--danger); font-style: normal; }

/* ---------- Result ---------- */
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.result-actions { display: flex; gap: 8px; }

.copy {
  border: 1px solid rgba(224, 116, 60, 0.6);
  background: none;
  color: var(--accent-bright);
  font-family: var(--serif);
  font-size: 0.88rem;
  padding: 7px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.12s ease;
}
.copy:hover { transform: translateY(-1px); }
.copy.copied { background: var(--accent); color: #fff; }

.ghost-outline {
  border-color: var(--panel-border);
  color: var(--muted);
}
.ghost-outline:hover { color: var(--text); }

.result {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--mono);
  font-size: 0.93rem;
  line-height: 1.6;
  background: var(--panel-inset);
  border: 1px solid rgba(255, 240, 220, 0.04);
  border-radius: 14px;
  padding: 18px;
  max-height: 52vh;
  overflow-y: auto;
}

/* ---------- Teach Aaron ---------- */
.teach-wrap {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.teach-summary {
  cursor: pointer;
  margin-bottom: 0;
  list-style: none;
  user-select: none;
  transition: color 0.2s ease;
}
.teach-summary::-webkit-details-marker { display: none; }
.teach-summary::after { content: " +"; color: var(--accent); }
.teach-wrap[open] .teach-summary::after { content: " −"; }
.teach-wrap[open] .teach-summary { margin-bottom: 10px; color: var(--muted); }

.teach-hint {
  color: var(--faint);
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.5;
  margin-bottom: 12px;
}

#contextBox {
  width: 100%;
  background: var(--panel-inset);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 0.95rem;
  line-height: 1.55;
  padding: 12px;
  resize: vertical;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#contextBox::placeholder { color: var(--faint); font-style: italic; }
#contextBox:focus {
  outline: none;
  border-color: rgba(224, 116, 60, 0.5);
  box-shadow: 0 0 0 3px rgba(224, 116, 60, 0.1);
}

/* ---------- History ---------- */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--panel-inset);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s ease;
}
.history-item:hover { border-color: rgba(224, 116, 60, 0.28); }

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-mode {
  color: var(--accent);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.history-copy {
  border: 1px solid rgba(224, 116, 60, 0.5);
  background: none;
  color: var(--accent-bright);
  font-family: var(--serif);
  font-size: 0.8rem;
  padding: 4px 14px;
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.15s ease, color 0.15s ease;
}
.history-copy:hover { background: rgba(224, 116, 60, 0.12); }
.history-copy.copied { background: var(--accent); color: #fff; border-color: var(--accent); }

.history-text {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
  font-family: var(--mono);
  white-space: pre-wrap;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-text.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

/* ---------- Spinner ---------- */
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--faint);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Entrances ---------- */
@media (prefers-reduced-motion: no-preference) {
  .stage, .result-wrap, .history-wrap, .top, .modes {
    animation: rise 0.5s ease both;
  }
  .modes { animation-delay: 0.06s; }
  .stage { animation-delay: 0.12s; }
  .result-wrap, .history-wrap { animation-delay: 0.18s; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
