:root {
  --ink: #102a43;
  --muted: #617386;
  --line: #d5e0e7;
  --paper: #f3f6f8;
  --white: #ffffff;
  --green: #087f7c;
  --green-dark: #075f5d;
  --blue: #1356a0;
  --blue-soft: #e8f1fa;
  --coral: #d85f49;
  --yellow: #f2c14e;
  --error: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
  font-family: "Manrope", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
textarea,
input,
select {
  font: inherit;
  letter-spacing: 0;
}
button {
  color: inherit;
  cursor: pointer;
}

.topbar {
  height: 78px;
  padding: 0 clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 14px rgba(16, 42, 67, 0.05);
}

.brand {
  display: flex;
  align-items: center;
  height: 100%;
  text-decoration: none;
}
.brand-logo {
  display: block;
  width: auto;
  height: 64px;
  max-width: min(260px, 70vw);
  object-fit: contain;
}

.workspace {
  width: 100%;
  max-width: 1440px;
  min-height: calc(100vh - 124px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  background: var(--white);
  border-inline: 1px solid var(--line);
}
.translator {
  min-width: 0;
  padding: clamp(32px, 4vw, 58px) clamp(24px, 5vw, 72px) 48px;
  border-right: 1px solid var(--line);
  background: var(--paper);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 18px;
  align-content: start;
}
.mode-toolbar {
  grid-column: 1 / -1;
  grid-row: 1;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}
.mode-toolbar label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.mode-toolbar select {
  min-width: 190px;
  height: 42px;
  padding: 0 38px 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
}
#outputMode {
  min-width: 250px;
}
.mode-toolbar select:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}
.history {
  min-width: 0;
  padding: 40px 28px;
  background: var(--white);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}
h2 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 27px;
  line-height: 1.1;
}
#historyTitle {
  font-size: 32px;
}

.language-bar {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: 1fr 52px 1fr;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--white);
  box-shadow: 0 8px 28px rgba(16, 42, 67, 0.06);
  overflow: hidden;
}
.language-select {
  min-width: 0;
  min-height: 72px;
  padding: 16px 20px;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 13px;
  text-align: left;
}
.language-select.target {
  border-left: 1px solid var(--line);
}
.language-code {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
}
.language-code.korean {
  background: #fff0e8;
  color: #a7422d;
  font-size: 14px;
}
.language-select span:last-child {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.language-select strong {
  font-size: 14px;
}
.language-select small {
  color: var(--muted);
  font-size: 11px;
}
.swap-button {
  position: relative;
  z-index: 2;
  width: 38px;
  height: 38px;
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  font-size: 20px;
}
.swap-button {
  display: grid;
  place-items: center;
  cursor: default;
}

.input-area {
  grid-column: 1 / -1;
  grid-row: 3;
  min-height: 140px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: #eaf1f3;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px rgba(16, 42, 67, 0.06);
}
.record-panel {
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.visualizer {
  height: 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.visualizer span {
  width: 3px;
  height: 7px;
  background: #aeb7b0;
  border-radius: 2px;
}
.recording .visualizer span {
  background: var(--coral);
  animation: pulse 0.8s ease-in-out infinite alternate;
}
.recording .visualizer span:nth-child(2),
.recording .visualizer span:nth-child(6) {
  animation-delay: 0.15s;
}
.recording .visualizer span:nth-child(3),
.recording .visualizer span:nth-child(5) {
  animation-delay: 0.3s;
}
.recording .visualizer span:nth-child(4) {
  animation-delay: 0.45s;
}
@keyframes pulse {
  to {
    height: 22px;
  }
}

.record-button {
  min-width: 196px;
  height: 50px;
  padding: 0 24px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(19, 86, 160, 0.2);
  transition:
    background 0.18s ease,
    transform 0.18s ease;
}
.record-button:hover {
  background: #0f477f;
  transform: translateY(-1px);
}
.record-button:disabled {
  cursor: wait;
  opacity: 0.7;
}
.mic-symbol {
  width: 12px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 7px;
  position: relative;
}
.mic-symbol::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 14px;
  height: 8px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  transform: translateX(-50%);
}
.recording .record-button {
  background: var(--coral);
  box-shadow: 0 8px 18px rgba(216, 95, 73, 0.2);
}
.recording.paused .record-button {
  background: var(--muted);
  box-shadow: none;
}
.recording.paused .visualizer span {
  animation-play-state: paused;
  background: var(--muted);
}
.record-time {
  margin: 8px 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.transcript-block {
  position: relative;
  min-width: 0;
  height: 286px;
  min-height: 286px;
  max-height: 286px;
  grid-column: 1;
  grid-row: 4;
  margin-top: 24px;
  margin-bottom: 12px;
  padding: 20px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 6px;
  background: var(--white);
  box-shadow: 0 8px 25px rgba(16, 42, 67, 0.07);
  display: flex;
  flex-direction: column;
}
.transcript-block label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
textarea {
  width: 100%;
  flex: 1;
  resize: none;
  height: 160px;
  min-height: 0;
  max-height: 160px;
  padding: 0 0 24px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  line-height: 1.6;
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: none;
}
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 127, 124, 0.1);
}
.character-count {
  position: absolute;
  right: 20px;
  bottom: 18px;
  color: var(--muted);
  font-size: 10px;
}
.character-count b {
  font-weight: 500;
}

.action-row {
  grid-column: 1 / -1;
  grid-row: 5;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.message {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.message.error {
  color: var(--error);
}
.translate-button {
  flex: 0 0 auto;
  min-width: 150px;
  height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}
.translate-button:hover {
  background: var(--blue);
}
.translate-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.result-panel {
  min-width: 0;
  height: 286px;
  min-height: 286px;
  max-height: 286px;
  grid-column: 2;
  grid-row: 4;
  margin-top: 24px;
  margin-bottom: 12px;
  padding: 20px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 6px;
  background: var(--white);
  box-shadow: 0 8px 25px rgba(16, 42, 67, 0.07);
  display: flex;
  flex-direction: column;
}
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  text-transform: uppercase;
}
.language-badge {
  padding: 4px 7px;
  border-radius: 4px;
  background: var(--blue-soft);
  color: var(--blue);
}
.translated-text {
  flex: 1;
  height: 160px;
  min-height: 0;
  max-height: 160px;
  margin: 20px 0;
  padding-right: 8px;
  font-family: "Newsreader", Georgia, serif;
  font-size: 18px;
  line-height: 1.3;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: anywhere;
}
.user-menu {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}
.user-menu a,
.user-menu button {
  padding: 7px 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}
.user-menu a:hover,
.user-menu button:hover {
  background: var(--blue-soft);
}
textarea,
.translated-text {
  scrollbar-color: #8f8f8f transparent;
  scrollbar-width: thin;
}
textarea::-webkit-scrollbar,
.translated-text::-webkit-scrollbar {
  width: 10px;
}
textarea::-webkit-scrollbar-track,
.translated-text::-webkit-scrollbar-track {
  background: transparent;
}
textarea::-webkit-scrollbar-thumb,
.translated-text::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #8f8f8f;
  background-clip: padding-box;
}
.translated-text:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
  font-family: "Manrope", Arial, sans-serif;
  font-size: 13px;
  font-weight: 400;
}
.result-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
.result-actions button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  font-size: 12px;
  font-weight: 600;
}
.result-actions button:hover {
  border-color: var(--green);
  color: var(--green);
}

.history-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}
.history-heading button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--blue);
  font-size: 18px;
}
.history-heading button:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}
.history-list {
  display: flex;
  flex-direction: column;
}
.history-item {
  position: relative;
  padding: 18px 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.16s ease;
}
.history-item:first-child {
  border-top: 1px solid var(--line);
}
.history-item:hover {
  background: #f5f9fb;
}
.history-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
}
.history-item p {
  margin: 4px 30px 4px 0;
  overflow-wrap: anywhere;
  white-space: normal;
  font-size: 13.5px;
  line-height: 1.55;
}
.history-item p.translated {
  color: var(--blue);
  font-weight: 700;
}
.history-delete {
  position: absolute;
  right: 0;
  bottom: 16px;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: #929c95;
  font-size: 18px;
}
.history-delete:hover {
  color: var(--error);
}
.history-empty {
  padding: 35px 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}
footer {
  height: 46px;
  padding: 0 clamp(20px, 4vw, 64px);
  border-top: 1px solid var(--line);
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}
.hidden {
  display: none !important;
}
.guest-mode .record-panel,
.guest-mode .mode-toolbar select,
.guest-mode .translate-button,
.guest-mode .result-actions,
.guest-mode .history-heading button {
  cursor: not-allowed;
  opacity: 0.55;
}
.guest-mode textarea {
  cursor: default;
}
.speech-to-translate-mode #speakButton {
  display: none;
}
.speech-to-translate-mode .translate-button {
  display: none;
}
.speech-to-translate-mode .transcript-block {
  display: none;
}
.speech-to-translate-mode .result-panel {
  grid-column: 1 / -1;
  grid-row: 4;
}
.speech-to-translate-mode .action-row {
  grid-row: 5;
}
button:focus-visible,
textarea:focus-visible,
.history-item:focus-visible {
  outline: 3px solid rgba(19, 86, 160, 0.28);
  outline-offset: 2px;
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .translator {
    grid-template-columns: 1fr;
    border-right: 0;
  }
  .transcript-block {
    grid-column: 1;
    grid-row: 4;
  }
  .result-panel {
    grid-column: 1;
    grid-row: 5;
    margin-top: 0;
  }
  .action-row {
    grid-row: 6;
  }
  .history {
    border-top: 1px solid var(--line);
    padding: 36px 24px;
  }
}

@media (max-width: 620px) {
  .topbar {
    height: 68px;
    padding-inline: 16px;
  }
  .brand-logo {
    height: 56px;
    max-width: 190px;
  }
  .user-menu {
    gap: 3px;
  }
  #currentUser {
    display: none;
  }
  .workspace {
    min-height: calc(100vh - 114px);
    border-inline: 0;
  }
  .translator {
    padding: 24px 16px 36px;
  }
  .mode-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .mode-toolbar select {
    width: 100%;
    min-width: 0;
  }
  .language-bar {
    grid-template-columns: 1fr 40px 1fr;
  }
  .language-select {
    min-height: 64px;
    padding: 12px 8px;
    gap: 7px;
  }
  .language-code {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }
  .language-select small {
    display: none;
  }
  .input-area {
    min-height: 132px;
  }
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }
  .translate-button {
    width: 100%;
  }
}
