/* ─────────────────────────────────────────────────────────────────────────────
   Thai Karaoke — Design v5
   Sharp, modern, premium. Karaoke as hero.
───────────────────────────────────────────────────────────────────────────── */

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

/* ── Tokens ── */

:root {
  --ease-out:  cubic-bezier(0.23, 1, 0.32, 1);
  --ease-snap: cubic-bezier(0.34, 1.2, 0.64, 1);

  --bg:         #090908;
  --surface:    #111110;
  --surface-hi: #1a1a18;
  --surface-2:  #222220;

  --border:     rgba(255, 255, 255, 0.07);
  --border-hi:  rgba(255, 255, 255, 0.12);
  --border-focus: rgba(255, 255, 255, 0.22);

  --text:       #ddd8cf;
  --text-2:     #706b62;
  --text-3:     #3a3834;

  --amber:      #e8a020;
  --amber-dim:  rgba(232, 160, 32, 0.15);
  --amber-glow: rgba(232, 160, 32, 0.06);

  --green:  #3ecf8e;
  --yellow: #d4a017;
  --red:    #e05252;

  --font-ui:      'Outfit', system-ui, sans-serif;
  --font-thai:    'Sarabun', 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
  --font-serif:   Georgia, serif;
  --font-display: 'Outfit', var(--font-thai), system-ui, sans-serif;
  --size-display: 24px;

  --r:     16px;
  --r-sm:  9px;
  --r-xs:  6px;
}

[data-theme="light"] {
  --bg:         #f2ede6;
  --surface:    #faf8f5;
  --surface-hi: #edeae4;
  --surface-2:  #e5e1da;
  --border:     rgba(0, 0, 0, 0.07);
  --border-hi:  rgba(0, 0, 0, 0.12);
  --border-focus: rgba(0, 0, 0, 0.28);
  --text:       #1c1a16;
  --text-2:     #7a7368;
  --text-3:     #c0b8ae;
  --amber-dim:  rgba(232, 160, 32, 0.18);
  --amber-glow: rgba(232, 160, 32, 0.08);
  color-scheme: light;
}

[data-theme="light"] .header         { background: rgba(242, 237, 230, 0.92); }
[data-theme="light"] .input-bar      { background: rgba(242, 237, 230, 0.96); }
[data-theme="light"] .input-inner    { background: var(--surface); border-color: var(--border-hi); }
[data-theme="light"] .input-inner:focus-within { border-color: var(--border-focus); }
[data-theme="light"] .card           { box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 6px 20px rgba(0,0,0,0.06); }
[data-theme="light"] .karaoke-card   { box-shadow: 0 0 0 1px rgba(232,160,32,0.1), 0 1px 3px rgba(0,0,0,0.06), 0 6px 20px rgba(0,0,0,0.07); }
[data-theme="light"] .karaoke-line .syllable { color: var(--text); }
[data-theme="light"] .karaoke-line .hyphen   { color: var(--text-3); }
[data-theme="light"] .font-panel     { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
[data-theme="light"] .trans-block:last-child { background: var(--surface-hi); }

/* ── Base ── */

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  touch-action: manipulation;
}

/* ── App shell ── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Header ── */

.header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(9, 9, 8, 0.90);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 48px;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.logo-thai {
  font-family: var(--font-thai);
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-2);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.logo-sep { color: var(--text-3); font-size: 0.75rem; }

.logo-en {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-3);
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* ── Pills ── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 27px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 0.67rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
  .pill:hover { color: var(--text); border-color: var(--border-hi); background: var(--surface-hi); }
}
.pill:active { transform: scale(0.93); }
.pill:focus-visible { outline: 2px solid var(--amber-dim); outline-offset: 2px; }

/* ── Status dot ── */

.status-dot {
  width: 7px;
  height: 27px;
  border-radius: 999px;
  background: var(--red);
  border: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 350ms ease, width 180ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .status-dot:hover { width: 11px; }
}
.status-dot:active         { transform: scale(0.88); }
.status-dot.green          { background: var(--green); }
.status-dot.red            { background: var(--red); }
.status-dot.pulsing        { background: var(--yellow); animation: pulse 2s ease-in-out infinite; }

.api-dot, .api-modal-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--yellow);
  flex-shrink: 0;
  transition: background 350ms ease;
}
.api-dot.green,  .api-modal-dot.green  { background: var(--green); }
.api-dot.red,    .api-modal-dot.red    { background: var(--red); }
.api-dot.yellow, .api-modal-dot.yellow { background: var(--yellow); animation: pulse 2s ease-in-out infinite; }

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

/* ── Font picker ── */

.font-picker { position: relative; }

.font-panel {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  min-width: 196px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
  transform: translateY(-4px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms var(--ease-out), opacity 150ms ease;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.font-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

.font-select {
  width: 100%;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-xs);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  padding: 4px 6px;
  cursor: pointer;
  outline: none;
  appearance: auto;
}

.size-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-a {
  color: var(--text-2);
  font-size: 0.72rem;
  line-height: 1;
  flex-shrink: 0;
}
.size-a--lg { font-size: 1.1rem; }

.font-slider {
  flex: 1;
  accent-color: var(--amber);
  cursor: pointer;
  height: 4px;
}

/* ── Overlay / modal ── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.overlay.open { opacity: 1; pointer-events: all; }

.overlay-modal {
  width: 360px;
  max-width: calc(100vw - 40px);
  background: #161614;
  border: 1px solid var(--border-hi);
  border-radius: 20px;
  padding: 24px;
  transform: scale(0.96) translateY(8px);
  opacity: 0;
  transition: transform 220ms var(--ease-out), opacity 180ms ease;
}

.overlay.open .overlay-modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.overlay-title {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-2);
}

.overlay-input {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-xs);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 10px 12px;
  outline: none;
  letter-spacing: 0.03em;
  transition: border-color 140ms ease;
}
.overlay-input:focus { border-color: var(--border-focus); }
.overlay-input::placeholder { color: var(--text-3); }

.overlay-status {
  margin-top: 10px;
  font-size: 0.73rem;
  min-height: 1.4em;
  color: var(--text-2);
  transition: color 180ms ease;
}
.overlay-status.ok   { color: var(--green); }
.overlay-status.fail { color: var(--red); }
.overlay-status.busy { color: var(--text-2); }

/* ── Workspace ── */

.workspace {
  flex: 1;
  width: 100%;
  max-width: 660px;
  margin: 0 auto;
  padding: 32px 20px 160px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Cards ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow:
    0 1px 2px rgba(0,0,0,0.6),
    0 4px 16px rgba(0,0,0,0.35),
    0 16px 48px rgba(0,0,0,0.18);
}

/* ── Input bar — full-width fixed bottom ── */

.input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: rgba(9, 9, 8, 0.95);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}

/* Rounded inner container — the actual chat box */
.input-inner {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  transition: border-color 160ms ease;
  overflow: hidden;
}

.input-inner:focus-within {
  border-color: var(--border-focus);
}

/* Legacy selector — keep working for .input-card refs in JS */
.input-card {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: rgba(9, 9, 8, 0.95);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}

[data-theme="light"] .input-card {
  background: rgba(242, 237, 230, 0.96);
}

.input-card .input-inner {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  transition: border-color 160ms ease;
  overflow: hidden;
}

.input-card .input-inner:focus-within {
  border-color: var(--border-focus);
}

/* Attachments strip */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 0;
}
.attachments:empty { display: none; }

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px 4px 6px;
  font-size: 0.7rem;
  color: var(--text-2);
}
.attachment img { width: 24px; height: 24px; object-fit: cover; border-radius: 3px; }
.attachment .remove-btn {
  background: none; border: none; color: var(--text-3); cursor: pointer;
  font-size: 1rem; padding: 0 2px; line-height: 1;
  transition: color 120ms ease;
}
.attachment .remove-btn:hover { color: var(--red); }

/* Textarea */
.input-card textarea {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-thai);
  font-size: 1rem;
  line-height: 1.6;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  overflow-y: auto;
  caret-color: var(--amber);
  padding: 11px 16px 6px;
}

.input-card textarea::placeholder { color: var(--text-3); }
.input-card textarea::-webkit-scrollbar { width: 3px; }
.input-card textarea::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

/* Toolbar */
.input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 6px;
}

.tool-group { display: flex; gap: 1px; }

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: none;
  border: none;
  border-radius: var(--r-xs);
  color: var(--text-3);
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .tool-btn:hover { color: var(--text-2); background: var(--surface-hi); }
}
.tool-btn:active { transform: scale(0.87); }
.tool-btn:focus-visible { outline: 2px solid var(--amber-dim); outline-offset: 2px; }
.tool-btn--dim { opacity: 0.35; pointer-events: none; color: var(--text-3) !important; }
.tool-btn--send { color: var(--amber); }

@media (hover: hover) and (pointer: fine) {
  .tool-btn--send:not(.tool-btn--dim):hover { background: var(--amber-dim); }
}

.tool-btn.recording {
  color: var(--red) !important;
  animation: pulse 0.8s ease-in-out infinite;
}

/* Loading overlay inside input */
.input-loading {
  position: absolute;
  inset: 0;
  border-radius: 13px;
  background: rgba(9, 9, 8, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease;
  overflow: hidden;
  z-index: 10;
}

.input-card.loading .input-loading {
  opacity: 1;
  pointer-events: all;
}

.input-loading-scan {
  position: absolute;
  bottom: 0; left: 0;
  width: 40%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--amber) 40%, var(--amber) 60%, transparent);
  opacity: 0;
  transform: translateX(-100%);
}

.input-card.loading .input-loading-scan {
  opacity: 1;
  animation: scan 1.3s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes scan {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ── Error ── */

.error-msg {
  display: none;
  font-size: 0.74rem;
  color: var(--red);
  padding-left: 4px;
  line-height: 1.5;
}
.error-msg.visible { display: block; }

/* ── Output ── */

.output {
  display: none;
  flex-direction: column;
  gap: 0;
}
.output.has-content { display: flex; }
.output:not(.has-content) { display: none !important; }
.output.loading { opacity: 0.25; pointer-events: none; transition: opacity 200ms ease; }

.result {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Entry animation */
.result.animating .card {
  animation: card-rise 380ms var(--ease-out) both;
}
.result.animating .card:nth-child(1) { animation-delay: 0ms; }
.result.animating .card:nth-child(2) { animation-delay: 60ms; }
.result.animating .card:nth-child(3) { animation-delay: 110ms; }

@keyframes card-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Card labels ── */

.card-label {
  display: block;
  font-size: 0.63rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 12px;
}

.karaoke-card .card-label { color: rgba(232, 160, 32, 0.8); }
.note-card    .card-label { color: rgba(77, 191, 176, 0.85); }

/* ── Karaoke card ── */

.karaoke-card {
  padding: 24px 26px 28px;
  border-left: 3px solid var(--amber);
  background: linear-gradient(135deg,
    rgba(232, 160, 32, 0.05) 0%,
    var(--surface) 40%
  );
  box-shadow:
    0 0 0 1px rgba(232,160,32,0.05),
    0 2px 6px rgba(0,0,0,0.65),
    0 10px 36px rgba(0,0,0,0.42),
    0 36px 72px rgba(0,0,0,0.18);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header .card-label { margin-bottom: 0; }

.trans-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.trans-block-header .card-label { margin-bottom: 0; }

/* Copy + save buttons */
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  color: var(--text-3);
  cursor: pointer;
  font-size: 0.65rem;
  font-family: var(--font-ui);
  letter-spacing: 0.03em;
  padding: 3px 8px;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .copy-btn:hover { color: var(--text-2); border-color: var(--border-hi); background: var(--surface-hi); }
}
.copy-btn.copied { color: var(--green); border-color: rgba(62,207,142,0.25); }
.copy-btn:focus-visible { outline: 2px solid var(--amber-dim); outline-offset: 2px; }

.save-btn {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  background: none; border: none;
  border-radius: var(--r-xs);
  color: var(--text-3);
  cursor: pointer;
  transition: color 130ms ease, background 130ms ease;
  flex-shrink: 0;
}
@media (hover: hover) and (pointer: fine) {
  .save-btn:hover { color: var(--amber); background: var(--amber-dim); }
}
.save-btn.saved { color: var(--amber); }
.save-btn:focus-visible { outline: 2px solid var(--amber-dim); outline-offset: 2px; }

/* Karaoke text */
.karaoke-line {
  font-family: var(--font-display);
  font-size: calc(var(--size-display) * 1.14);
  line-height: 1.55;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.karaoke-line .karaoke-word  { display: inline; transition: opacity 150ms ease; }
.karaoke-line .syllable      { color: #ede8df; }
.karaoke-line .hyphen        { color: rgba(237,232,223,0.32); }
.karaoke-line .space         { display: inline-block; width: 0.45em; }

/* ── Translation card ── */

.translation-card { overflow: hidden; }

.translation-body { padding: 20px 24px; }

.trans-block { }

.trans-block:last-child {
  background: rgba(255,255,255,0.018);
  margin: 16px -24px -20px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
}

.thai-line {
  font-family: var(--font-display);
  font-size: var(--size-display);
  line-height: 1.7;
  color: var(--text);
}

/* Thai word tooltip */
.thai-word {
  position: relative;
  display: inline-block;
  vertical-align: bottom;
  cursor: pointer;
  touch-action: manipulation;
  border-bottom: 1px dotted var(--text-3);
  margin-right: 0.3em;
  transition: border-color 120ms ease, opacity 150ms ease;
}
.thai-canvas { display: block; }
.thai-sel {
  position: absolute;
  inset: 0;
  color: transparent;
  user-select: text;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
}

@media (hover: hover) and (pointer: fine) {
  .thai-word[data-meaning]:hover { border-bottom-color: var(--text-2); }
}

.thai-vowel { cursor: help; font-weight: 500; }
.thai-word.has-audio    { border-bottom-color: var(--amber); border-bottom-style: solid; }
.thai-word.speaking     { opacity: 0.4; transition: opacity 80ms ease; }
.word-chip.speaking     { opacity: 0.4; transition: opacity 80ms ease; }
/* Mobile sticky selection */
.thai-word--selected    { border-bottom: 2px solid var(--amber); }
.char-underline {
  position: absolute;
  bottom: 0;
  height: 2.5px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 1px;
  pointer-events: none;
}

/* Karaoke word tooltip */
.karaoke-word[data-meaning] { position: relative; cursor: help; }

.english-line {
  font-family: var(--font-display);
  font-size: calc(var(--size-display) * 0.58);
  color: var(--text-2);
  line-height: 1.75;
}

/* ── Word by word — collapsible ── */

.words-section { border-top: 1px solid var(--border); }

.words-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none; border: none;
  padding: 13px 24px;
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 0.77rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 130ms ease, background 130ms ease;
  text-align: left;
}

@media (hover: hover) and (pointer: fine) {
  .words-toggle:hover { background: var(--surface-hi); color: var(--text); }
}
.words-toggle:active { transform: scale(0.99); }

.chevron {
  color: var(--text-3);
  flex-shrink: 0;
  transition: transform 220ms var(--ease-out), color 130ms ease;
}
.words-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
  color: var(--text-2);
}

/* Accordion — grid height trick */
.words-content {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 280ms var(--ease-out);
}
.words-content.open { grid-template-rows: 1fr; }
.words-inner { overflow: hidden; padding: 0 24px; }
.words-content.open .words-inner { padding: 4px 24px 20px; }

/* Word chips */
.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.word-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 130ms ease, background 130ms ease, opacity 80ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .word-chip:hover {
    border-color: rgba(232, 160, 32, 0.3);
    background: rgba(232, 160, 32, 0.05);
  }
}

.chip-thai  { font-family: var(--font-display); font-size: 1rem; color: var(--text); line-height: 1.4; }
.chip-rom   { font-family: var(--font-mono); font-size: 0.64rem; color: var(--amber); letter-spacing: 0.02em; white-space: nowrap; }
.chip-eng   { font-size: 0.62rem; color: var(--text-2); letter-spacing: 0.01em; white-space: nowrap; }
.chip-class { font-family: var(--font-mono); font-size: 0.52rem; color: var(--text-3); letter-spacing: 0.08em; text-transform: uppercase; }

.literal-line {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-2);
  line-height: 1.7;
}

/* ── Note card ── */

.note-card { display: none; padding: 18px 24px; }

.note-card.visible {
  display: block;
  border-left: 3px solid rgba(77, 191, 176, 0.55);
  background: linear-gradient(100deg, rgba(77, 191, 176, 0.05) 0%, var(--surface) 55%);
}

.note-line {
  font-family: var(--font-display);
  font-size: 0.8rem;
  color: var(--text-2);
  line-height: 1.7;
  padding-left: 12px;
  border-left: 2px solid rgba(77, 191, 176, 0.45);
}

/* ── Loading dots ── */

.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.loading-dots span {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--bg);
  animation: bounce 1s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.4; }
  40%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Drag state ── */

.input-card.drag-over .input-inner {
  border-color: rgba(232, 160, 32, 0.5);
  box-shadow: 0 0 0 3px var(--amber-glow);
}

/* ── Karaoke card drag ── */
.karaoke-card[draggable="true"] { cursor: grab; }
.karaoke-card.is-dragging { opacity: 0.45; }

/* ── Dictionary panel ── */

.dict-panel {
  position: fixed;
  top: 48px; right: 0; bottom: 0;
  width: 268px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 280ms var(--ease-out), border-color 180ms ease;
  z-index: 200;
  box-shadow: -6px 0 28px rgba(0,0,0,0.3);
}
.dict-panel.open { transform: translateX(0); }
.dict-panel.drop-active {
  border-left-color: rgba(232, 160, 32, 0.55);
  box-shadow: -6px 0 36px rgba(232, 160, 32, 0.07);
}

.dict-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.dict-panel-title {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-2);
}

.dict-close-btn {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: none; border: none;
  border-radius: 5px;
  color: var(--text-3);
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .dict-close-btn:hover { color: var(--text); background: var(--surface-hi); }
}

.dict-drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 10px 12px;
  padding: 10px;
  border: 1px dashed var(--border-hi);
  border-radius: var(--r-xs);
  color: var(--text-3);
  font-size: 0.71rem;
  letter-spacing: 0.02em;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
  flex-shrink: 0;
}
.dict-panel.drop-active .dict-drop-zone {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-glow);
}

.dict-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dict-list::-webkit-scrollbar { width: 3px; }
.dict-list::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

.dict-entry {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 10px 10px 10px 12px;
  cursor: grab;
  transition: border-color 130ms ease, background 130ms ease;
  user-select: none;
}
@media (hover: hover) and (pointer: fine) {
  .dict-entry:hover { border-color: var(--border-hi); background: rgba(255,255,255,0.03); }
}
.dict-entry-chosen { opacity: 0.4; cursor: grabbing; }
.dict-entry-ghost {
  background: var(--amber-glow) !important;
  border: 1px dashed rgba(232,160,32,0.4) !important;
  opacity: 1 !important;
}
.dict-entry-ghost .dict-entry-body,
.dict-entry-ghost .dict-entry-del { opacity: 0; }

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

.dict-entry-karaoke {
  font-family: var(--font-mono);
  font-size: 0.77rem;
  color: var(--amber);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
  letter-spacing: -0.01em;
}

.dict-entry-english {
  font-size: 0.67rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dict-entry-del {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  flex-shrink: 0;
  background: none; border: none;
  border-radius: 4px;
  color: var(--text-3);
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
  margin-top: 1px;
}
@media (hover: hover) and (pointer: fine) {
  .dict-entry-del:hover { color: var(--red); background: rgba(224,82,82,0.1); }
}

.dict-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; padding: 24px;
  color: var(--text-3);
  text-align: center;
}
.dict-empty p { font-size: 0.74rem; line-height: 1.65; }

#dict-count:not(:empty)::before { content: '·\00a0'; }
#dict-count { font-size: 0.67rem; }

/* ── Character info card ── */

.char-card {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  box-shadow: 0 8px 36px rgba(0,0,0,0.55);
  overflow: hidden;
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transform-origin: top center;
  transition: opacity 120ms var(--ease-out), transform 120ms var(--ease-out);
}
.char-card.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.cc-panel {
  padding: 12px 14px;
  min-width: 128px;
  min-height: 158px;
  display: flex;
  flex-direction: column;
}
.cc-vsep {
  width: 1px;
  background: var(--border);
  margin: 10px 0;
  flex-shrink: 0;
  display: none;
}
.cc-panel--secondary { display: none; }
.char-card.has-secondary .cc-vsep,
.char-card.has-secondary .cc-panel--secondary { display: flex; }

.cc-glyph {
  font-family: var(--font-display);
  font-size: 2.5rem;
  line-height: 1.2;
  text-align: center;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  color: var(--text);
  user-select: none;
}

.cg-base        { color: var(--text); }
.cg-vowel       { color: var(--amber); }
.cg-placeholder { color: var(--text-3); }
.cg-mark        { color: var(--text-2); }

.cc-hero {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--amber);
  text-align: center;
  letter-spacing: 0.02em;
  line-height: 1.1;
  margin-bottom: 5px;
}

.cc-name {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-sub {
  font-family: var(--font-ui);
  font-size: 0.63rem;
  color: var(--text-2);
  text-align: center;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cc-panel--primary .cc-sub { font-size: 0.68rem; }

.cc-divider { height: 1px; background: var(--border); margin: 8px 0; }

.cc-props {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 8px;
  align-items: baseline;
}

.cc-key {
  font-family: var(--font-ui);
  font-size: 0.58rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.cc-val {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  color: var(--amber);
  white-space: nowrap;
}

/* ── Word tooltip ── */

.word-tip {
  position: fixed;
  z-index: 9998;
  pointer-events: none;
  background: var(--surface-hi);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(5px) scale(0.97);
  transition: opacity 120ms var(--ease-out), transform 120ms var(--ease-out);
}
.word-tip.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.word-tip-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.3;
  color: #ffffff;
  white-space: nowrap;
}

/* ── Responsive ── */

@media (max-width: 600px) {
  .header         { padding: 0 12px; height: 44px; }
  .logo           { min-width: 0; }
  .logo-en, .logo-sep { display: none; }
  .logo-thai      { font-size: 0.88rem; }
  .header-actions { gap: 4px; }
  .pill           { height: 25px; padding: 0 8px; font-size: 0.62rem; }
  .workspace      { padding: 18px 12px 160px; }
  :root           { --size-display: 20px; }
  .karaoke-line   { font-size: calc(var(--size-display) * 1.08); }
  .input-card     { padding: 8px 10px; }
  .input-card textarea { font-size: 1.1rem; }
  .tool-btn       { width: 36px; height: 36px; }
  .dict-panel     { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .font-panel     { right: 0; min-width: unset; width: calc(100vw - 24px); }
  .char-card      { max-width: calc(100vw - 16px); }
}

@media (max-width: 400px) {
  .logo-thai { font-size: 0.82rem; }
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:  0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
