* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  margin: 0;
  padding: 0;
  line-height: 1.5;
}
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.5px;
  font-weight: 700;
}
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
}
.subtitle {
  color: #94a3b8;
  margin: 0 0 24px;
  font-size: 14px;
  text-align: center;
}
.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.controls label { color: #94a3b8; font-size: 14px; }
.field { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
select {
  padding: 8px 12px;
  font-size: 14px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 8px;
}
button {
  padding: 10px 18px;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #3b82f6;
  color: white;
}
button.secondary { background: #475569; }
button.primary { background: #10b981; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.audio-toggle-label { color: #94a3b8; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; margin-left: 12px; }
.controls-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.history-toggle-btn {
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-width: 100px;
}

.history-panel {
  position: fixed;
  top: 60px;
  right: -380px;
  width: 360px;
  max-height: calc(100vh - 60px);
  background: #1e293b;
  border-left: 1px solid #334155;
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}
.history-panel.open {
  right: 0;
}
.history-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #334155;
  background: #1e293b;
}
.history-panel-header h2 {
  margin: 0;
  font-size: 16px;
  color: #fbbf24;
  font-weight: 600;
}
.history-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.history-close-btn:hover {
  background: #334155;
  color: #e2e8f0;
}
.history-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #334155;
  background: #1e293b;
}
.history-toggle {
  color: #94a3b8;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.history-toggle input { accent-color: #3b82f6; }
#clearHistory {
  background: #64748b;
  color: #e2e8f0;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
  margin-left: auto;
}
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 24px;
}
.badge {
  display: inline-block;
  background: #3b82f6;
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.korean {
  font-size: 40px;
  font-weight: 700;
  color: #fbbf24;
  margin: 0 0 10px;
  line-height: 1.4;
}
.translation {
  font-size: 18px;
  color: #e2e8f0;
  margin: 0 0 10px;
}
.concept {
  font-size: 14px;
  color: #a78bfa;
  border-top: 1px solid #334155;
  padding-top: 12px;
  margin-top: 16px;
}

.audio-section {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  text-align: center;
}
.playback-controls {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.speed-label { color: #94a3b8; font-size: 14px; white-space: nowrap; }
#speedSlider { width: 140px; cursor: pointer; accent-color: #3b82f6; }
#speedValue { font-size: 14px; color: #e2e8f0; min-width: 30px; }
.audio-hint { color: #94a3b8; font-size: 13px; font-style: italic; }

.reveal-section { text-align: center; margin: 16px 0; }
.sentence-content { margin-top: 16px; }

.decision {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 24px;
  margin-top: 20px;
}
.decision-question {
  font-size: 16px;
  color: #e2e8f0;
  margin: 0 0 14px;
  font-weight: 600;
}
.decision-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.decision-actions button {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  font-size: 14px;
}
.decision-actions button.secondary { background: #475569; }
.decision-actions button.primary { background: #10b981; }
#issueInput {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #334155;
}
#issueInput label { display: block; color: #94a3b8; font-size: 14px; margin-bottom: 8px; }
#issueInput textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  margin-bottom: 10px;
}
#status { margin-top: 10px; color: #4ade80; font-size: 14px; min-height: 20px; }
.error { color: #f87171; font-size: 14px; margin-top: 12px; min-height: 20px; }
.popup {
  position: fixed;
  background: #3b82f6;
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  z-index: 100;
  max-width: 320px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  pointer-events: none;
}
.popup.hidden { display: none !important; }
.hidden { display: none !important; }

.history-item {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 14px;
}
.history-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.history-level {
  background: #3b82f6;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.history-formality {
  background: #475569;
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.history-length {
  background: #64748b;
  color: #e2e8f0;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
}
.history-content {
  margin-bottom: 10px;
}
.history-korean {
  font-size: 22px;
  font-weight: 700;
  color: #fbbf24;
  margin: 0 0 6px;
  line-height: 1.4;
  word-break: keep-all;
}
.history-translation {
  font-size: 14px;
  color: #94a3b8;
  margin: 0 0 4px;
}
.history-concept {
  font-size: 12px;
  color: #a78bfa;
}
.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.history-btn {
  padding: 8px 14px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
}
.history-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.context-row {
  margin: 18px 0 6px;
}
.context-row label { display: block; color: #94a3b8; font-size: 14px; margin-bottom: 6px; }
.context-row textarea {
  width: 100%;
  min-height: 70px;
  padding: 10px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}