/* Translator — Apple-style monochrome UI */
:root {
  --bg: #ffffff;
  --card: #f5f5f7;
  --fg: #000000;
  --muted: #86868b;
  --border: rgba(0,0,0,.08);
  --pill-track: rgba(0,0,0,.05);
  --accent: #000000;
  --on-accent: #ffffff;
  --danger: #ff3b30;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --fg: #f5f5f7;
    --muted: #98989d;
    --border: rgba(255,255,255,.1);
    --pill-track: rgba(255,255,255,.07);
    --accent: #ffffff;
    --on-accent: #000000;
    --danger: #ff453a;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Arabic", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease;
}

main {
  max-width: 620px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px);
  padding-top: max(clamp(16px, 4vw, 32px), env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- header / language switch ---------- */
header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 0 22px;
}

.lang-switch {
  display: inline-flex;
  gap: 4px;
  background: var(--pill-track);
  border-radius: 999px;
  padding: 4px;
  border: 1px solid var(--border);
}

.lang-pill {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 10px 26px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s ease;
  min-width: 110px;
}
.lang-pill[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
.lang-pill:not([aria-selected="true"]):hover { color: var(--fg); }
.lang-pill:active { transform: scale(.96); }

/* ---------- panels ---------- */
.panel {
  background: var(--card);
  border-radius: 22px;
  padding: 20px 22px 14px;
  display: flex;
  flex-direction: column;
  transition: background .3s ease;
}

textarea#input {
  appearance: none;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: inherit;
  width: 100%;
  font: inherit;
  font-size: 23px;
  line-height: 1.45;
  min-height: 84px;
  caret-color: var(--fg);
}
textarea#input::placeholder { color: var(--muted); opacity: .7; }

.output-text {
  font-size: 23px;
  line-height: 1.55;
  min-height: 84px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.output-empty {
  font-size: 19px;
  color: var(--muted);
  min-height: 84px;
  display: flex;
  align-items: center;
}
.output-empty.hidden, .hidden { display: none !important; }

.output-text.loading { animation: breathe 1.1s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: .35; } 50% { opacity: .75; } }

/* ---------- panel action rows ---------- */
.panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  min-height: 52px;
}
.actions-right { display: flex; align-items: center; gap: 8px; }
.actions-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

/* ---------- dialect switch ---------- */
.dialect-switch {
  display: inline-flex;
  gap: 4px;
  background: var(--pill-track);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.dialect-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
}
.dialect-btn[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.dialect-btn:not([aria-selected="true"]):hover { color: var(--fg); }
.dialect-btn:active { transform: scale(.95); }
/* dimmed when Arabic is the input language (dialect only affects Arabic output) */
.dialect-switch.disabled { opacity: .4; pointer-events: none; }

.status { font-size: 13px; color: var(--muted); }

/* ---------- icon buttons ---------- */
.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--fg);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s ease;
  flex-shrink: 0;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(128,128,128,.15); }
.icon-btn:active { transform: scale(.9); }
.icon-btn.primary { background: var(--accent); color: var(--on-accent); }
.icon-btn.primary:hover { background: var(--accent); }
.icon-btn.recording { background: var(--danger); color: #fff; animation: pulse 1.4s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,59,48,.5); }
  70% { box-shadow: 0 0 0 14px rgba(255,59,48,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,59,48,0); }
}

#mic .ic-stop, #mic.recording .ic-mic { display: none; }
#mic.recording .ic-stop { display: block; }
#copy .ic-check, #copy.copied .ic-copy { display: none; }
#copy.copied .ic-check { display: block; }
#speak.speaking svg { animation: breathe .9s ease-in-out infinite; }

/* ---------- swap divider ---------- */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
}
.divider-line { flex: 1; height: 1px; background: var(--border); }

.swap-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s ease;
}
.swap-btn svg { width: 20px; height: 20px; transition: transform .3s ease; }
.swap-btn:hover { transform: scale(1.06); }
.swap-btn:active { transform: scale(.92); }
.swap-btn.flipped svg { transform: rotate(180deg); }

/* ---------- toggle switch ---------- */
.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.toggle-label { font-size: 13px; color: var(--muted); font-weight: 500; }

.toggle { position: relative; display: inline-block; width: 42px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--pill-track);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background .2s ease;
}
.toggle .slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 1px;
  top: 1px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s ease;
}
.toggle input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(16px); }

/* ---------- error ---------- */
.error {
  text-align: center;
  color: var(--danger);
  font-size: 14px;
  padding: 14px 0 0;
}

/* arabic typography refinement */
[dir="rtl"] { letter-spacing: 0 !important; }

/* ---------- conversation history ---------- */
.history-section {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}
.history-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.history-clear {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s ease;
}
.history-clear svg { width: 16px; height: 16px; }
.history-clear:hover { background: rgba(128,128,128,.15); color: var(--fg); }
.history-clear:active { transform: scale(.9); }

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

.history-item {
  background: var(--card);
  border-radius: 18px;
  padding: 14px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadein .25s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.history-row { display: flex; flex-direction: column; gap: 3px; }
.history-lang {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--muted);
}
.history-text {
  font-size: 17px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.history-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding-top: 2px;
  border-top: 1px solid var(--border);
}
.history-item-actions .icon-btn { width: 34px; height: 34px; }
.history-item-actions .icon-btn svg { width: 17px; height: 17px; }
