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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222f;
  --border: #2a2a3a;
  --primary: #7c6aef;
  --primary-glow: rgba(124, 106, 239, 0.3);
  --accent: #f472b6;
  --text: #e8e6f0;
  --text-dim: #8b87a0;
  --card-bg: #1e1e2a;
  --japanese: #ff6b9d;
  --chinese: #fbbf24;
  --spanish: #4ade80;
}

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.top-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-current,
.nav-link {
  font-size: 0.85rem;
  width: 120px;
  text-align: center;
  padding: 6px 0;
  border-radius: 8px;
}

.nav-current {
  font-weight: 600;
  color: #fff;
  background: var(--primary);
}

.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--text);
  border-color: var(--primary);
  background: var(--surface2);
}

.layout {
  display: flex;
  min-height: 100vh;
  justify-content: center;
  gap: 20px;
  padding: 20px;
}

.container {
  max-width: 700px;
  width: 100%;
  padding: 40px 0;
}

header {
  text-align: center;
  margin-bottom: 40px;
}

header h1 {
  font-size: 2.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

header .desc {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-top: 8px;
}

header .tip {
  color: var(--accent);
  font-size: 0.85rem;
  margin-top: 12px;
  padding: 8px 16px;
  background: rgba(244, 114, 182, 0.1);
  border: 1px solid rgba(244, 114, 182, 0.2);
  border-radius: 8px;
  display: inline-block;
}

.input-section {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid var(--border);
}

textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 1.05rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.6;
}

textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea::placeholder {
  color: var(--text-dim);
}

.input-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.char-count {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.char-count.over {
  color: #ef4444;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  gap: 12px;
}

.lang-toggle {
  display: flex;
  gap: 8px;
}

.lang-btn {
  padding: 10px 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
}

.convert-btn {
  padding: 12px 32px;
  background: linear-gradient(135deg, var(--primary), #6355d8);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.convert-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--primary-glow);
}

.convert-btn:active {
  transform: translateY(0);
}

.convert-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.hidden {
  display: none !important;
}

.result-section {
  margin-top: 32px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.result-header h2 {
  font-size: 1.3rem;
  font-weight: 500;
}

.tts-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-select {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
  max-width: 200px;
  transition: border-color 0.2s;
}

.voice-select:hover,
.voice-select:focus {
  border-color: var(--primary);
}

.voice-select option {
  background: var(--surface);
  color: var(--text);
}

.speed-btn {
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 36px;
}

.speed-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.speed-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tts-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tts-btn:hover {
  border-color: var(--primary);
  background: var(--surface2);
}

.tts-btn.playing {
  border-color: var(--accent);
  color: var(--accent);
}

.full-result-wrapper {
  position: relative;
  margin-bottom: 24px;
}

.full-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 0.95rem;
  line-height: 1.8;
  letter-spacing: 0.3px;
  word-break: break-word;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.result-char-count {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
}

.copy-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.copy-btn.copied {
  border-color: #22c55e;
  color: #22c55e;
}

.full-result.japanese {
  font-family: 'Noto Sans JP', 'Noto Sans KR', sans-serif;
  color: var(--japanese);
}

.full-result.chinese {
  font-family: 'Noto Sans SC', 'Noto Sans KR', sans-serif;
  color: var(--chinese);
}

.full-result.spanish {
  color: var(--spanish);
}

.word-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.word-cards-break {
  flex-basis: 100%;
  height: 12px;
}

.word-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  min-width: 80px;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}

.word-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.word-card .original {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.word-card .converted {
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.4;
}

.word-card .converted.japanese {
  font-family: 'Noto Sans JP', sans-serif;
  color: var(--japanese);
}

.word-card .converted.chinese {
  font-family: 'Noto Sans SC', sans-serif;
  color: var(--chinese);
}

.server-tts-section {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.server-tts-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.server-tts-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.server-tts-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
}

.server-tts-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.tts-remaining {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.debug-check {
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.debug-check input {
  cursor: pointer;
}

.server-tts-saved {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.server-tts-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.server-tts-item-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 80px;
}

.server-tts-item-text {
  font-size: 0.72rem;
  color: var(--text-dim);
  word-break: break-all;
  opacity: 0.6;
}

.server-tts-play-btn {
  padding: 6px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.server-tts-play-btn:hover {
  border-color: var(--primary);
}

.server-tts-play-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.server-tts-item audio {
  flex: 1;
  height: 36px;
  border-radius: 8px;
}

.word-card .converted.spanish {
  color: var(--spanish);
}

.word-card.speaking {
  border-color: var(--primary);
  background: rgba(124, 106, 239, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--primary-glow);
}

.full-result .highlight {
  background: rgba(124, 106, 239, 0.25);
  border-radius: 4px;
  padding: 2px 4px;
}

.typecast-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.typecast-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.typecast-header h3 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-dim);
}

.tooltip-wrap {
  position: relative;
  display: inline-flex;
}

.help-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  transition: all 0.2s;
}

.help-icon:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tooltip {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  line-height: 1.5;
}

.tooltip a {
  color: var(--primary);
  text-decoration: underline;
}

.tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border);
}

.tooltip-wrap:hover .tooltip {
  display: block;
}

.typecast-row {
  display: flex;
  gap: 10px;
}

.typecast-key {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.typecast-key:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.typecast-key::placeholder {
  color: var(--text-dim);
}

.typecast-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #e65c00, #f09819);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.typecast-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(230, 92, 0, 0.3);
}

.typecast-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.typecast-audio {
  width: 100%;
  margin-top: 14px;
  border-radius: 10px;
}

.history-section {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

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

.history-header h2 {
  font-size: 1.3rem;
  font-weight: 500;
}

.clear-history-btn {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.clear-history-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

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

.history-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  border-color: var(--primary);
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.history-item-lang {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text-dim);
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item-date {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.history-delete-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.history-delete-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.history-item-original {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-audio-badge {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(230, 92, 0, 0.2);
  color: #f09819;
  margin-left: 6px;
}

.history-play-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.72rem;
  font-family: 'Noto Sans KR', sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.history-play-btn:hover {
  border-color: #f09819;
  color: #f09819;
}

.history-audio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.history-item-result {
  font-size: 0.95rem;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-result.japanese { color: var(--japanese); font-family: 'Noto Sans JP', sans-serif; }
.history-item-result.chinese { color: var(--chinese); font-family: 'Noto Sans SC', sans-serif; }
.history-item-result.spanish { color: var(--spanish); }

@media (max-width: 600px) {
  .container {
    padding: 20px 0;
  }

  header h1 {
    font-size: 2.2rem;
  }

  .controls {
    flex-direction: column;
  }

  .lang-toggle {
    width: 100%;
  }

  .lang-btn {
    flex: 1;
  }

  .convert-btn {
    width: 100%;
  }

  .full-result {
    font-size: 0.85rem;
  }

  .typecast-row {
    flex-direction: column;
  }
}
