:root {
  --bg: #14171c;
  --panel: #1e232b;
  --panel-2: #272d37;
  --text: #f4f5f7;
  --muted: #9aa3b2;
  --accent: #2fbf71;
  --accent-ink: #06210f;
  --rec: #e5484d;
  --busy: #f5a524;
  --radius: 22px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 16px; touch-action: manipulation; }
button:disabled { opacity: .35; cursor: default; }

.screen {
  min-height: 100%;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 720px;
  margin: 0 auto;
}

/* login */
#login { justify-content: center; }
.login-box { text-align: center; display: flex; flex-direction: column; gap: 16px; }
.logo { font-size: 64px; }
h1 { margin: 0; font-size: 30px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#code {
  font-size: 28px; text-align: center; letter-spacing: .3em;
  padding: 16px; border-radius: 16px; border: 2px solid var(--panel-2);
  background: var(--panel); outline: none;
}
#code:focus { border-color: var(--accent); }
.error { color: var(--rec); margin: 0; }

.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 16px 20px; font-size: 20px; }
.secondary { background: var(--panel-2); padding: 14px 10px; font-size: 18px; font-weight: 600; }
.ghost { background: transparent; color: var(--muted); padding: 10px 12px; font-size: 16px; }
.ghost.icon { font-size: 24px; padding: 6px 10px; }

/* header */
header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.header-actions { display: flex; align-items: center; gap: 4px; }
.chip { background: var(--panel); padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 17px; white-space: nowrap; }

/* result */
.result {
  flex: 1 1 auto;
  min-height: 34vh;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-user-select: text; user-select: text;
}
.direction { font-size: 22px; font-weight: 700; color: var(--muted); min-height: 1.2em; }
.original { font-size: 17px; color: var(--muted); }
.translation { font-size: clamp(28px, 7.5vw, 44px); line-height: 1.2; font-weight: 700; flex: 1; overflow-wrap: anywhere; }
.translation.placeholder { font-size: 22px; font-weight: 500; color: var(--muted); }
.translation.error { color: var(--busy); font-size: 26px; }
.timing { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.2em; }

/* controls */
.controls { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 12px; align-items: center; }
.talk {
  aspect-ratio: 1;
  width: 100%;
  max-width: 220px;
  justify-self: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 8px 28px rgba(47, 191, 113, .35);
  transition: transform .08s ease, background .15s ease;
}
.talk:active { transform: scale(.96); }
.talk-icon { font-size: 54px; line-height: 1; }
.talk-label { font-size: 20px; font-weight: 800; margin-top: 6px; }
.talk.recording { background: var(--rec); color: #fff; box-shadow: 0 0 0 0 rgba(229, 72, 77, .6); animation: pulse 1.2s infinite; }
.talk.listening { background: var(--accent); color: var(--accent-ink); animation: breathe 2s ease-in-out infinite; }
.talk.speaking { background: var(--panel-2); color: var(--text); box-shadow: none; }
@keyframes breathe { 50% { opacity: .75; } }
.toggle { width: 100%; }
.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.talk.busy { background: var(--busy); color: #2b1a00; box-shadow: none; }
.talk.busy .talk-icon { animation: spin 1s linear infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(229,72,77,.6); } 70% { box-shadow: 0 0 0 26px rgba(229,72,77,0); } 100% { box-shadow: 0 0 0 0 rgba(229,72,77,0); } }
@keyframes spin { to { transform: rotate(360deg); } }

.type-form { display: flex; gap: 8px; }
.type-form input { flex: 1; min-width: 0; padding: 14px; border-radius: 14px; border: 2px solid var(--panel-2); background: var(--panel); outline: none; font-size: 20px; }
.type-form input:focus { border-color: var(--accent); }

/* history */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { background: var(--panel); border-radius: 14px; padding: 10px 12px; font-size: 15px; color: var(--muted); }
.history li b { color: var(--text); font-weight: 600; }

/* language switch */
.lang-switch { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.lang-switch button { background: var(--panel-2); padding: 10px 4px; font-size: 16px; font-weight: 600; border: 2px solid transparent; }
.lang-switch button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.login-box .lang-switch { margin-top: 12px; }

/* settings dialog */
dialog { border: 0; border-radius: var(--radius); background: var(--panel); color: var(--text); width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.settings-form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.settings-form h2 { margin: 0; }
.settings-form h3 { margin: 8px 0 0; font-size: 17px; color: var(--muted); }
.translation, .placeholder { white-space: pre-line; }
.hint { margin: 0; color: var(--muted); font-size: 15px; }
#notes-text { width: 100%; background: var(--bg); border: 2px solid var(--panel-2); border-radius: 14px; padding: 12px; font-size: 15px; resize: vertical; -webkit-user-select: text; user-select: text; }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* hairstyle try-on */
.photo-row { display: flex; gap: 10px; }
.photo-row button { flex: 1; }
.photo-dialog { width: 100vw; max-width: 720px; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: auto; }
.photo-wrap { padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.photo-wrap header h2 { margin: 0; font-size: 22px; }
.ph-step { display: flex; flex-direction: column; gap: 12px; }
.ph-text { margin: 0; font-size: 18px; white-space: pre-line; }
.ph-text.big { font-size: 19px; font-weight: 600; }
.ph-input { padding: 14px; border-radius: 14px; border: 2px solid var(--panel-2); background: var(--bg); outline: none; font-size: 18px; -webkit-user-select: text; user-select: text; }
.ph-input:focus { border-color: var(--accent); }
.file-btn { display: block; text-align: center; border-radius: 16px; cursor: pointer; }
.ph-preview { width: 100%; max-height: 42dvh; object-fit: contain; border-radius: 16px; background: var(--bg); }
.ph-spinner { font-size: 64px; text-align: center; margin-top: 18dvh; animation: spin 1.6s linear infinite; }
#ph-working { align-items: center; text-align: center; }
.ph-tabs { display: flex; gap: 6px; }
.ph-tabs button { flex: 1; min-width: 0; padding: 4px 4px 6px; border-radius: 12px; border: 2px solid var(--panel-2); background: var(--bg); color: var(--muted); font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ph-thumb { position: relative; width: 100%; height: 13dvh; min-height: 64px; display: flex; align-items: center; justify-content: center; border-radius: 9px; overflow: hidden; background: var(--panel); }
.ph-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-thumb img:not([src]) { display: none; }
.ph-thumb-wait { position: absolute; font-size: 24px; animation: spin 1.6s linear infinite; }
.ph-thumb-wait[hidden] { display: none; }
.ph-tabs button.active { border-color: var(--accent); color: inherit; font-weight: 600; }
.ph-views { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; border-radius: 18px; }
.ph-views::-webkit-scrollbar { display: none; }
.ph-view { flex: 0 0 100%; scroll-snap-align: center; position: relative; background: var(--bg); min-height: 40dvh; display: flex; align-items: center; justify-content: center; }
.ph-view img { display: block; width: 100%; max-height: 46dvh; object-fit: contain; }
.ph-view img:not([src]), .ph-view img[src=""] { display: none; }
.ph-view-wait { position: absolute; font-size: 48px; animation: spin 1.6s linear infinite; }
.ph-view-wait[hidden] { display: none; }
.ph-change-row { display: flex; gap: 10px; }
.ph-change-row button { flex: 1; }
.ph-change-row .recording { background: var(--rec); color: #fff; }
.ph-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ph-compare figure { margin: 0; }
.ph-compare img { width: 100%; border-radius: 14px; display: block; }
.ph-compare figcaption { text-align: center; color: var(--muted); font-size: 15px; margin-top: 4px; }
.ph-feri { white-space: pre-line; font-size: 20px; line-height: 1.4; background: var(--bg); border-radius: 14px; padding: 12px 14px; -webkit-user-select: text; user-select: text; }
