/* ============================================================
   百万畅销书作家 — Typewriter English Learning App
   Premium typewriter-themed CSS with dark metallic UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Special+Elite&family=Courier+Prime:wght@400;700&display=swap');

/* ---------- CSS Custom Properties ---------- */
:root {
  --bg-deep: #1a0f0a;
  --bg-dark: #2c1a11;
  --wood-base: #381c10;
  --wood-grain: #291209;
  --paper: #f4ecdf;
  --paper-line: rgba(0, 0, 0, 0.05);
  --ink: #1a1a24;
  --ink-light: #2c2c3b;
  --accent-gold: #cfa878;
  --accent-gold-dim: #997850;
  --error-red: #cc3333;
  --error-red-bg: rgba(204, 51, 51, 0.15);
  --success-green: #2e8857;
  --success-green-bg: rgba(46, 136, 87, 0.1);
  --panel-bg: #1c1511;
  --font-typewriter: 'Caveat', 'Dancing Script', cursive;
  --font-mono: 'Courier Prime', monospace;
  --line-height: 40px;
  --paper-pad-left: 60px;
  --margin-line-left: 48px;
}

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

html {
  height: 100%;
}

body {
  background-color: var(--wood-base);
  background-image: 
    radial-gradient(circle at 30% 20%, rgba(255, 200, 100, 0.15) 0%, transparent 60%),
    repeating-linear-gradient(90deg, transparent, transparent 15px, rgba(0,0,0,0.05) 15px, rgba(0,0,0,0.05) 30px),
    linear-gradient(to right, var(--wood-base) 0%, var(--wood-grain) 100%);
  font-family: var(--font-typewriter);
  font-size: 26px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--paper);
  padding-bottom: 40px;
  overflow-x: hidden;
  box-shadow: inset 0 0 100px rgba(0,0,0,0.8);
}

/* ---------- Header ---------- */
.header {
  padding: 28px 0 8px;
  text-align: center;
  user-select: none;
}

.header h1 {
  font-size: 2.4rem;
  color: var(--accent-gold);
  text-shadow:
    0 0 20px rgba(212, 165, 116, 0.3),
    2px 2px 4px rgba(0, 0, 0, 0.6);
  letter-spacing: 6px;
  font-weight: 400;
}

.subtitle {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--metal-light);
  margin-top: 4px;
  letter-spacing: 5px;
  text-transform: uppercase;
}

/* ---------- Typewriter Container -> Desk Surface ---------- */
#typewriter {
  width: 780px;
  max-width: 95vw;
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 30px;
  position: relative;
  border-radius: 4px;
}

/* We don't need the metal roller anymore. Remove all roller CSS. */
#paper-roller {
  display: none;
}


/* ---------- Document Dropdown (anchored from footer) ---------- */
.doc-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-family: 'Inter', sans-serif;
  z-index: 999;
  margin-bottom: 6px;
}

.doc-dropdown.hidden {
  display: none;
}

.doc-empty {
  padding: 20px;
  text-align: center;
  color: #667;
  font-size: 0.85rem;
}

.doc-item {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background 0.15s;
}

.doc-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.doc-item:last-child {
  border-bottom: none;
}

.doc-item-text {
  font-size: 0.85rem;
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.doc-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: #667;
}

.doc-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  opacity: 0.5;
  transition: opacity 0.2s;
  padding: 2px 4px;
}

.doc-delete:hover {
  opacity: 1;
}

/* ---------- Paper ---------- */
#paper {
  background: var(--paper);
  background-image:
    repeating-linear-gradient(
      transparent 0px,
      transparent calc(var(--line-height) - 1px),
      var(--paper-line) calc(var(--line-height) - 1px),
      var(--paper-line) var(--line-height)
    );
  flex: 1;
  min-height: 500px;
  overflow-y: auto;
  padding: 30px 50px 60px var(--paper-pad-left);
  position: relative;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.6),
    0 2px 5px rgba(0, 0, 0, 0.4),
    inset 0 0 80px rgba(139, 119, 90, 0.1);
  border-radius: 4px;
  line-height: var(--line-height);
  font-size: 32px; /* Bigger font for Caveat */
  color: var(--ink);
  scrollbar-width: none;
  cursor: text;
}

#paper::-webkit-scrollbar {
  display: none;
}

/* Left margin red line */
#paper::before {
  content: '';
  position: absolute;
  left: var(--margin-line-left);
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(220, 60, 60, 0.25);
  pointer-events: none;
}

/* Subtle paper grain overlay */
#paper::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.02'/%3E%3C/svg%3E");
  pointer-events: none;
  opacity: 0.5;
}

/* ---------- Text Content ---------- */
#text-content {
  position: relative;
  z-index: 1;
}

/* ---------- Placeholder ---------- */
#placeholder {
  position: absolute;
  top: 15%;
  left: 50%;
  transform: translate(-50%, 0);
  text-align: center;
  color: rgba(0,0,0,0.25);
  font-size: 1.5rem;
  pointer-events: none;
  transition: opacity 0.8s ease;
  z-index: 2;
  line-height: 1.8;
  font-family: var(--font-typewriter);
}

#placeholder small {
  opacity: 0.5;
  font-size: 0.85rem;
}

#placeholder.fade-out {
  opacity: 0;
}

/* ---------- Text Lines ---------- */
.text-line {
  min-height: var(--line-height);
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

/* ---------- Characters ---------- */
.char {
  display: inline-block;
  position: relative;
  white-space: pre-wrap; /* Preserve spaces width */
}

.ink-bleed {
  animation: penWrite 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes penWrite {
  0% {
    opacity: 0.2;
    clip-path: polygon(0 0, 0 0, 0 120%, 0 120%);
    filter: blur(2px);
  }
  100% {
    opacity: 1;
    clip-path: polygon(0 0, 120% 0, 120% 120%, 0 120%);
    filter: blur(0);
  }
}

/* ---------- Cursor (Fountain Pen) ---------- */
#cursor {
  display: inline-block;
  width: 16px;
  height: 24px;
  position: relative;
  vertical-align: bottom;
  margin-left: 2px;
  transition: opacity 0.3s;
  /* subtle idle breathing */
  animation: penIdle 3s ease-in-out infinite;
}

#cursor::after {
  content: '🪶';
  position: absolute;
  bottom: -2px;
  left: 2px;
  font-size: 32px;
  line-height: 1;
  /* The Mac quill emoji has the tip at bottom-left and feather at top-right.
     We rotate it slightly so the tip points perfectly at the text and the feather leans back. */
  transform-origin: bottom left;
  transform: rotate(-15deg);
  filter: drop-shadow(6px 12px 5px rgba(0,0,0,0.4));
  pointer-events: none;
}

@keyframes penIdle {
  0%, 100% { transform: translateY(0) rotate(-15deg); }
  50% { transform: translateY(-2px) rotate(-13deg); }
}

/* Quick scratch animation triggered by JS */
#cursor.writing {
  animation: penScratch 0.15s ease-out;
}

@keyframes penScratch {
  0% { transform: translate(0, 0) rotate(-15deg); }
  30% { transform: translate(3px, -4px) rotate(-22deg); }
  70% { transform: translate(-1px, 2px) rotate(-11deg); }
  100% { transform: translate(0, 0) rotate(-15deg); }
}

/* Cursor paused (when checking grammar) */
#cursor.paused {
  animation: none;
  opacity: 0.4;
  transform: translateY(-5px) rotate(15deg);
  transition: all 0.3s ease;
}

/* ---------- Error Styling ---------- */
.char-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: var(--error-red);
  text-underline-offset: 3px;
  color: var(--error-red);
  background: rgba(204, 51, 51, 0.2); /* Highlight background in case wavy line fails */
  border-radius: 2px;
  transition: all 0.3s ease;
}

.char-corrected {
  text-decoration: line-through;
  color: #aaa;
  opacity: 0.5;
  transition: all 0.4s ease;
  user-select: none;
}

/* Correction inline text */
.correction {
  color: var(--success-green);
  font-weight: bold;
  animation: correctionReveal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline;
  position: relative;
}

@keyframes correctionReveal {
  0% {
    opacity: 0;
    transform: translateY(-6px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Repeat error flash background */
.char-repeat-error {
  background: var(--error-red-bg);
  border-radius: 2px;
  animation: repeatFlash 0.6s ease;
}

@keyframes repeatFlash {
  0%, 100% { background: transparent; }
  25% { background: rgba(231, 76, 60, 0.35); }
  50% { background: var(--error-red-bg); }
  75% { background: rgba(231, 76, 60, 0.25); }
}

/* ---------- Floating Speak Button ---------- */
#speak-selection-btn {
  position: absolute;
  z-index: 9999;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(46, 136, 87, 0.9);
  color: #fff;
  font-size: 15px;
  line-height: 32px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#speak-selection-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

#speak-selection-btn:hover {
  background: rgba(46, 136, 87, 1);
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(46, 136, 87, 0.4);
}

#speak-selection-btn.speaking {
  animation: speakPulse 0.6s ease;
}

@keyframes speakPulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------- Checking Indicator ---------- */
.checking-indicator {
  display: inline-block;
  color: #bbb;
  font-size: 15px;
  margin-left: 6px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---------- Sentence OK Checkmark ---------- */
.sentence-ok {
  color: var(--success-green);
  display: inline-block;
  margin-left: 6px;
  animation: checkPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-size: 16px;
}

@keyframes checkPop {
  0% {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.3) rotate(5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* ---------- Typewriter Base ---------- */
#typewriter-base {
  background: linear-gradient(180deg, var(--metal-mid) 0%, var(--metal-dark) 60%, #222238 100%);
  height: 48px;
  border-radius: 0 0 18px 18px;
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--metal-light);
  letter-spacing: 8px;
  text-transform: uppercase;
  user-select: none;
  opacity: 0.7;
}

/* ---------- Hidden Input ---------- */
#hidden-input {
  position: fixed;
  left: -9999px;
  top: -9999px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* ---------- Desk Objects (Diegetic UI) ---------- */
.desk-object {
  position: fixed;
  cursor: pointer;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.desk-item-shadow {
  position: absolute;
  bottom: -5px;
  left: 5px;
  right: -5px;
  height: 20px;
  background: rgba(0,0,0,0.6);
  filter: blur(10px);
  border-radius: 50%;
  z-index: -1;
}

/* Notebook (Error Bank) */
#error-bank-toggle {
  top: 60px;
  right: 60px;
  width: 90px;
  height: 130px;
  transform: rotate(5deg);
}

#error-bank-toggle:hover {
  transform: scale(1.05) rotate(0deg);
}

.desk-item-notebook {
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, #4a2c11 0%, #5c3a21 5%, #4a2c11 100%);
  border-radius: 4px 10px 10px 4px;
  box-shadow: 
    inset 4px 0 10px rgba(0,0,0,0.6),
    inset -2px 0 5px rgba(255,255,255,0.1),
    4px 8px 15px rgba(0,0,0,0.5);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cfa878;
  font-family: 'Playfair Display', serif;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  padding: 10px;
  border-left: 6px solid #291209;
}

.desk-item-notebook::after {
  content: 'ERRORS';
  opacity: 0.7;
}

#error-bank-toggle .error-count {
  position: absolute;
  top: -10px;
  right: -10px;
  background: #a32222;
  color: #f4ecdf;
  border-radius: 50%;
  min-width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-family: var(--font-typewriter);
  font-weight: bold;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  border: 2px solid #5c3a21;
}

/* ---------- Overlay ---------- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Error Bank Panel ---------- */
#error-bank-panel {
  position: fixed;
  top: 0;
  right: -450px;
  width: 420px;
  height: 100vh;
  height: 100dvh;
  background: var(--panel-bg);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.6);
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

#error-bank-panel.open {
  right: 0;
}

/* Panel Header */
.panel-header {
  padding: 28px 24px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.panel-header h2 {
  font-family: var(--font-typewriter);
  color: var(--accent-gold);
  font-size: 1.4rem;
  font-weight: 400;
  letter-spacing: 1px;
}

.panel-close {
  background: none;
  border: none;
  color: #666;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
  line-height: 1;
}

.panel-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

/* Panel Stats */
.panel-stats {
  padding: 16px 24px;
  display: flex;
  gap: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.stat-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-number {
  font-size: 2rem;
  color: var(--accent-gold);
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: 0.72rem;
  color: #667;
  margin-top: 6px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Error List */
.error-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.error-list::-webkit-scrollbar {
  width: 4px;
}

.error-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: #445;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
  margin-bottom: 6px;
  color: #556;
}

.empty-state small {
  font-size: 0.8rem;
  color: #445;
}

/* Error Item */
.error-item {
  background: rgba(255, 255, 255, 0.025);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border-left: 3px solid var(--error-red);
  transition: all 0.2s ease;
}

.error-item:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(2px);
}

.error-text,
.error-corrections {
  margin-bottom: 6px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.error-text .wrong,
.error-corrections .wrong {
  color: var(--error-red);
  text-decoration: line-through;
  opacity: 0.85;
}

.error-text .arrow,
.error-corrections .arrow {
  color: #556;
  margin: 0 8px;
  font-size: 0.85rem;
}

.error-text .correct,
.error-corrections .correct {
  color: var(--success-green);
  font-weight: 700;
}

.error-message {
  font-size: 0.78rem;
  color: #778;
  margin-bottom: 8px;
  line-height: 1.4;
  font-family: var(--font-mono);
}

.error-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: #556;
}

.error-category {
  background: rgba(212, 165, 116, 0.15);
  color: var(--accent-gold);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.68rem;
  letter-spacing: 0.5px;
}

.error-count-badge {
  color: var(--error-red);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* Error Explanation (bilingual) */
.error-explanation {
  margin: 8px 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border-left: 2px solid var(--accent-gold-dim);
}

.explanation-en {
  font-size: 0.82rem;
  color: #aab;
  line-height: 1.5;
  margin-bottom: 4px;
}

.explanation-zh {
  font-size: 0.82rem;
  color: #889;
  line-height: 1.5;
  margin-bottom: 8px;
}

.explanation-example {
  font-size: 0.78rem;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.example-label {
  color: var(--accent-gold);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.example-wrong {
  color: var(--error-red);
  text-decoration: line-through;
  opacity: 0.85;
}

.example-correct {
  color: var(--success-green);
  font-weight: 600;
}

/* Error Q&A */
.error-ask-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #778;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
  margin-right: 4px;
}

.error-ask-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

.error-qa-area {
  margin-top: 4px;
}

.qa-input-wrap {
  display: flex;
  gap: 6px;
  margin: 8px 0 4px;
}

.qa-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #ccc;
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.2s;
}

.qa-input:focus {
  border-color: var(--accent-gold);
}

.qa-send-btn {
  background: var(--accent-gold);
  color: #1a1a2e;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.qa-send-btn:hover {
  opacity: 0.85;
}

.qa-thread {
  margin: 8px 0 4px;
}

.qa-question {
  font-size: 0.8rem;
  color: var(--accent-gold);
  margin-bottom: 6px;
  font-family: 'Inter', sans-serif;
}

.qa-answer {
  font-size: 0.82rem;
  color: #bbc;
  line-height: 1.6;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border-left: 3px solid var(--accent-gold);
  font-family: 'Inter', sans-serif;
}

.qa-answer.loading {
  color: #667;
  animation: pulse 1.2s ease-in-out infinite;
}

.qa-answer code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.qa-answer strong {
  color: #dde;
}

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

/* Panel Footer */
.panel-footer {
  padding: 14px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.clear-btn {
  width: 100%;
  padding: 10px;
  background: rgba(231, 76, 60, 0.1);
  color: var(--error-red);
  border: 1px solid rgba(231, 76, 60, 0.2);
  border-radius: 8px;
  font-family: var(--font-typewriter);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.clear-btn:hover {
  background: rgba(231, 76, 60, 0.2);
  border-color: rgba(231, 76, 60, 0.4);
}

/* ---------- Status Bar ---------- */
#status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 15, 26, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: #556;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  font-family: var(--font-mono);
  z-index: 50;
  letter-spacing: 0.5px;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.status-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-hint {
  opacity: 0.5;
  font-size: 0.68rem;
}

.status-sep {
  opacity: 0.2;
  margin: 0 2px;
}

.status-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #667;
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
}

.status-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #aab;
  border-color: rgba(255, 255, 255, 0.15);
}

/* Floating Mic Button */
#mic-container {
  position: fixed;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 60;
  gap: 4px;
}

#mic-lang {
  font-family: 'Inter', sans-serif;
  font-size: 0.65rem;
  font-weight: 700;
  color: #667;
  background: rgba(15, 15, 26, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  letter-spacing: 0.5px;
}

#mic-lang:hover {
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

#mic-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mic-side-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 15, 26, 0.9);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  -webkit-tap-highlight-color: transparent;
  color: #889;
}

.mic-side-btn:hover {
  border-color: rgba(255, 255, 255, 0.25);
  color: #bbc;
}

.mic-side-btn:active {
  background: rgba(255, 255, 255, 0.08);
  transform: scale(0.92);
}

#mic-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(15, 15, 26, 0.95);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  -webkit-tap-highlight-color: transparent;
}

#mic-toggle:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(30, 28, 25, 0.95);
}

#mic-toggle:active,
#mic-container.listening #mic-toggle {
  border-color: rgba(231, 76, 60, 0.7);
  background: rgba(231, 76, 60, 0.15);
  box-shadow: 0 0 20px rgba(231, 76, 60, 0.3);
}

#mic-container.listening #mic-toggle {
  animation: mic-glow 1.5s ease-in-out infinite;
}

@keyframes mic-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(231, 76, 60, 0.3); }
  50% { box-shadow: 0 0 24px rgba(231, 76, 60, 0.5); }
}

#mic-container.listening #mic-lang {
  color: #e74c3c;
  border-color: rgba(231, 76, 60, 0.4);
}

#mic-status {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  color: var(--accent-gold);
  max-width: 280px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.2s;
  background: rgba(15, 15, 26, 0.9);
  padding: 2px 10px;
  border-radius: 8px;
  min-height: 18px;
}

#mic-status.active {
  opacity: 1;
}

/* ---------- Offline Indicator ---------- */
.offline-tag {
  color: #667;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  margin-left: 6px;
}

/* Retry Button */
.retry-btn {
  display: inline-block;
  font-size: 20px;
  color: var(--accent-gold);
  cursor: pointer;
  margin-left: 6px;
  transition: color 0.2s, transform 0.2s;
  user-select: none;
  vertical-align: middle;
}

.retry-btn:hover {
  color: var(--success-green);
  transform: scale(1.2);
}

.retry-btn.spinning {
  animation: retrySpin 0.8s linear infinite;
  color: var(--success-green);
  pointer-events: none;
}

.retry-btn.shake {
  animation: retryShake 0.4s ease;
  color: var(--error-red);
}

@keyframes retrySpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes retryShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  #typewriter {
    max-width: 98vw;
  }

  #paper {
    padding-left: 44px;
    padding-right: 30px;
    font-size: 16px;
  }

  #paper::before {
    left: 34px;
  }

  :root {
    --paper-pad-left: 44px;
    --margin-line-left: 34px;
  }

  .header h1 {
    font-size: 1.6rem;
    letter-spacing: 3px;
  }

  .subtitle {
    font-size: 0.65rem;
    letter-spacing: 3px;
  }
}

@media (max-width: 500px) {
  #error-bank-panel {
    width: 100%;
    right: -100%;
  }

  #error-bank-toggle {
    top: 20px;
    right: 20px;
    transform: scale(0.8) rotate(5deg);
  }

  .header h1 {
    font-size: 1.5rem;
  }

  #paper {
    padding-left: 20px;
    font-size: 24px;
    line-height: 32px;
  }

  #paper::before {
    left: 22px;
  }

  .roller-knob {
    width: 24px;
    height: 24px;
  }

  #assistant-panel {
    width: 100%;
    right: -100%;
  }

  #assistant-toggle {
    bottom: 20px;
    right: 20px;
    transform: scale(0.8) rotate(-10deg);
  }
}

/* ---------- Assistant Bell (Toggle) ---------- */
#assistant-toggle {
  bottom: 60px;
  right: 60px;
  width: 70px;
  height: 70px;
  transform: rotate(-10deg);
}

#assistant-toggle:hover {
  transform: scale(1.05) translateY(-5px) rotate(0deg);
}

.desk-item-assistant {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 30% 30%, #ffd060, #b8860b, #4a3304);
  border-radius: 50%;
  box-shadow: 
    inset -5px -5px 15px rgba(0,0,0,0.7),
    4px 10px 20px rgba(0,0,0,0.5);
  position: relative;
}

.desk-item-assistant::after {
  content: '';
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 20px;
  background: linear-gradient(to right, #b8860b, #ffd060, #4a3304);
  border-radius: 6px 6px 0 0;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.4);
}



/* ---------- Assistant Overlay ---------- */
#assistant-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#assistant-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Assistant Panel ---------- */
#assistant-panel {
  position: fixed;
  top: 0;
  right: -450px;
  width: 420px;
  height: 100vh;
  height: 100dvh;
  background: var(--panel-bg);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.6);
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

#assistant-panel.open {
  right: 0;
}

/* ---------- Chat Messages Area ---------- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* ---------- Chat Bubbles ---------- */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  animation: msgAppear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

@keyframes msgAppear {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* User messages: right-aligned, gold tint */
.chat-user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.2), rgba(212, 165, 116, 0.1));
  color: var(--paper);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(212, 165, 116, 0.15);
}

/* Bot messages: left-aligned, darker */
.chat-bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  color: #ccc;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-bot strong {
  color: #fff;
}

.chat-bot code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-gold);
}

.chat-bot em {
  color: #999;
  font-style: italic;
}

/* ---------- Typing Indicator ---------- */
.chat-typing {
  padding: 12px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #667;
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ---------- Chat Input Area ---------- */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--paper);
  font-family: var(--font-typewriter);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

/* ---------- Settings Modal ---------- */
#settings-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

#settings-overlay.active {
  opacity: 1;
  visibility: visible;
}

#settings-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -45%);
  width: 400px;
  background: var(--paper-bg);
  border-radius: 8px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5), inset 0 0 100px rgba(180, 160, 130, 0.2);
  z-index: 2001;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: var(--font-secondary);
  color: #333;
}

#settings-modal.open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%);
}

#settings-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

#settings-modal h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

#settings-modal .modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #666;
}

#settings-modal .modal-body {
  padding: 20px;
}

.settings-hint {
  font-size: 0.9rem;
  color: #666;
  margin-top: 0;
  margin-bottom: 20px;
  line-height: 1.4;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.85rem;
  font-weight: bold;
  color: #444;
}

.form-group select,
.form-group input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  box-sizing: border-box;
}

.form-group select {
  font-family: var(--font-secondary);
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: #888;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.1);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.checkbox-group label {
  margin: 0;
  cursor: pointer;
  font-weight: normal;
  color: #555;
}

.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid rgba(0,0,0,0.1);
  text-align: right;
}

.primary-btn {
  background: #333;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
}

.primary-btn:hover {
  background: #000;
}

/* Update Status Bar Right */
.status-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

#settings-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity 0.2s;
  padding: 0;
}

#settings-toggle:hover {
  opacity: 1;
}

.chat-input-area input::placeholder {
  color: #556;
}

.chat-input-area input:focus {
  border-color: rgba(91, 143, 185, 0.4);
  background: rgba(255, 255, 255, 0.08);
}

.chat-input-area button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8fb9, #3a6d8c);
  color: #fff;
  border: none;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-input-area button:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 10px rgba(91, 143, 185, 0.3);
}


