/* ── Variables ── */
:root {
  --background: #FFF9E6;
  --foreground: #2D3436;
  --primary: #4A90D9;
  --secondary: #FF8C42;
  --accent: #6BCB77;
  --card: #FFFFFF;
  --border: rgba(45,52,54,0.12);
  --muted: rgba(45,52,54,0.4);
  --danger: #e74c3c;
  --danger-bg: #fdf0ef;
}

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

html { scroll-behavior: smooth; height: 100%; }

body {
  background: var(--background);
  color: var(--foreground);
  font-family: "Comic Neue", "Comic Sans MS", cursive, sans-serif;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  overflow: hidden;
}

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

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.header-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.03em;
}

.header-badge {
  background: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.9);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ── Body ── */
.body {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 16px;
  padding: 16px 24px;
  overflow: hidden;
}

/* ── Voice Box ── */
.voice-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 2px solid rgba(107,203,119,0.3);
  border-radius: 14px;
  padding: 12px 16px;
  flex-shrink: 0;
}

.voice-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.voice-lang-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 2px;
}

.voice-interim {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s;
}

.voice-interim.active { color: var(--foreground); }

/* ── Mic ── */
.mic-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.mic-ripple-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 9999px;
  border: 3px solid var(--accent);
  animation: mic-ripple 1.5s ease-out infinite;
  opacity: 0;
}
.mic-ripple-ring:nth-child(2) { animation-delay: 0.5s; }
.mic-ripple-ring:nth-child(3) { animation-delay: 1s; }
.mic-ripple-ring.hidden { display: none; }

@keyframes mic-ripple {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(2.2); opacity: 0; }
}

.mic-icon {
  position: relative;
  z-index: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: rgba(45,52,54,0.08);
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.mic-icon.listening {
  background: var(--accent);
  color: #fff;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-icon {
  background: transparent;
  padding: 6px;
  color: var(--muted);
  border-radius: 8px;
}
.btn-icon:hover { background: rgba(45,52,54,0.06); }

.btn-icon.accent { color: var(--accent); background: rgba(107,203,119,0.1); }
.btn-icon.accent:hover { background: rgba(107,203,119,0.2); }

.btn-icon.danger { color: var(--danger); }
.btn-icon.danger:hover { background: var(--danger-bg); }

.btn-icon.primary { color: var(--primary); background: rgba(74,144,217,0.1); }
.btn-icon.primary:hover { background: rgba(74,144,217,0.2); }

.btn-header {
  background: rgba(255,255,255,0.2);
  color: #fff;
  padding: 6px 12px;
  font-size: 0.8rem;
}
.btn-header:hover { background: rgba(255,255,255,0.3); }

/* ── Lang Badge ── */
.lang-badge-wrap {
  position: relative;
  flex-shrink: 0;
}

.lang-badge {
  background: rgba(45,52,54,0.08);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background 0.15s;
}
.lang-badge:hover { background: rgba(45,52,54,0.14); }
.lang-badge:disabled { opacity: 0.4; cursor: not-allowed; }

.lang-popup {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 100;
  width: 160px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  overflow: hidden;
  max-height: 260px;
  overflow-y: auto;
  display: none;
}

.lang-popup.open { display: block; }

.lang-option {
  width: 100%;
  text-align: left;
  padding: 9px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--foreground);
  transition: background 0.12s;
}
.lang-option:hover { background: rgba(45,52,54,0.05); }
.lang-option.selected { background: rgba(107,203,119,0.15); color: var(--accent); }

/* ── Content Box ── */
.content-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 2px solid rgba(74,144,217,0.2);
  border-radius: 18px;
  overflow: hidden;
  min-height: 0;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 2px solid rgba(74,144,217,0.1);
  flex-shrink: 0;
  gap: 8px;
}

.toolbar-left {
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.punct-btn {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.punct-btn:hover {
  background: rgba(107,203,119,0.1);
  color: var(--accent);
  border-color: rgba(107,203,119,0.3);
}

.toolbar-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Content Area ── */
.content-area {
  flex: 1;
  background: var(--card);
  padding: 20px 24px;
  overflow-y: auto;
}

.content-placeholder {
  font-size: 1rem;
  font-style: italic;
  color: var(--muted);
}

.words-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 1.2rem;
  line-height: 1.8;
  align-items: center;
}

/* ── Word Chip ── */
.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(45,52,54,0.05);
  border-radius: 8px;
  padding: 2px 8px;
  font-weight: 700;
  color: var(--foreground);
  transition: background 0.12s, color 0.12s;
  user-select: none;
}
.word-chip:hover { background: rgba(107,203,119,0.15); color: var(--accent); }

.word-chip.punct {
  color: var(--muted);
  font-size: 1rem;
  background: rgba(45,52,54,0.04);
}

.word-chip.newline {
  font-size: 0.7rem;
  font-style: italic;
  color: var(--muted);
  background: rgba(45,52,54,0.04);
  width: 100%;
}

.word-text { cursor: pointer; }

.word-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(45,52,54,0.25);
  font-size: 0.75rem;
  line-height: 1;
  padding: 0 2px;
  font-family: inherit;
  transition: color 0.12s;
}
.word-delete:hover { color: var(--danger); }

/* ── Inline Edit Input ── */
.word-edit-input {
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--card);
  color: var(--foreground);
  outline: none;
  width: 120px;
}

/* ── Not Supported Banner ── */
.not-supported {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  text-align: center;
  padding: 24px;
}

.not-supported p {
  font-size: 1rem;
  font-weight: 700;
  color: var(--danger);
  max-width: 360px;
}

.not-supported small {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── API Info Banner ── */
.api-info {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  padding: 6px 16px;
  flex-shrink: 0;
}

.api-info a { color: var(--primary); text-decoration: none; }
.api-info a:hover { text-decoration: underline; }

.word-chip { cursor: grab; }
.word-chip.dragging { opacity: 0.4; cursor: grabbing; }
.word-chip.drag-over {
  outline: 2px dashed var(--accent);
  background: rgba(107,203,119,0.15);
}

/* ── Copied feedback ── */
.btn-icon.copied { color: var(--accent); }

/* ── Animations ── */
@keyframes pop-in {
  0%   { opacity: 0; transform: scale(0.88) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.pop-in { animation: pop-in 0.25s ease-out both; }

/* ── Responsive ── */
@media (max-width: 480px) {
  .header { padding: 10px 16px; }
  .body { padding: 12px 16px; gap: 12px; }
  .content-area { padding: 14px 16px; }
  .words-wrap { font-size: 1rem; }
  .word-edit-input { font-size: 1rem; width: 100px; }
}
