@font-face {
  font-family: "Noto Naskh Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/NotoNaskhArabic-Regular-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF,
    U+FE70-FE74, U+FE76-FEFC;
}

@font-face {
  font-family: "Noto Naskh Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/NotoNaskhArabic-Regular-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #f5f3f0;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6660;
  --border: #ddd8d1;
  --primary: #1f6f4c;
  --primary-active: #175a3d;
  --secondary: #ece8e2;
  --secondary-text: #4a453f;
  --danger: #b3341c;
  --chip-on-bg: #1f6f4c;
  --chip-on-text: #ffffff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  position: fixed;
  overflow: hidden;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  height: var(--app-h, 100dvh);
}

button, input, textarea {
  font-family: inherit;
}

.screen {
  height: var(--app-h, 100dvh);
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ---------- Login screen ---------- */

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.login-form label {
  font-size: 20px;
}

#login-code {
  font-size: 20px;
  padding: 12px 14px;
  text-align: center;
  letter-spacing: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}

#login-code:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.error-text {
  color: var(--danger);
  font-size: 16px;
}

#login-submit {
  font-size: 18px;
  padding: 12px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
}

#login-submit:active {
  background: var(--primary-active);
}

/* ---------- Main screen ---------- */

#main-screen {
  padding-top: calc(40px + var(--safe-top));
  padding-left: calc(4px + var(--safe-left));
  padding-right: calc(4px + var(--safe-right));
}

.icon-btn {
  position: absolute;
  top: calc(6px + var(--safe-top));
  left: calc(6px + var(--safe-left));
  width: 30px;
  height: 30px;
  min-width: 44px;
  min-height: 44px;
  margin: -7px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.icon-btn:active {
  background: var(--secondary);
}

.empty-queue {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 18px;
  color: var(--muted);
}

.work-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 8px 8px 8px;
}

.source-block {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: clamp(17px, 2.4vh + 8px, 24px);
  line-height: 1.6;
  direction: rtl;
  text-align: right;
}

#translation-input {
  flex: 0 0 auto;
  min-height: 66px;
  max-height: 45%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  resize: none;
  font-size: 18px;
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

#translation-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

@media (max-height: 520px) {
  #translation-input {
    max-height: min(45%, 160px);
  }
}

.flag-row {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  gap: 6px;
  overflow-x: auto;
}

.flag-chip {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-text);
  font-size: 13px;
  line-height: 1.2;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flag-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.flag-chip:has(input:checked) {
  background: var(--chip-on-bg);
  color: var(--chip-on-text);
  border-color: var(--chip-on-bg);
}

.error-banner {
  flex: 0 0 auto;
  background: #fbe6e1;
  color: var(--danger);
  border: 1px solid #f0b8a9;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  text-align: center;
}

.bottom-bar {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding-bottom: var(--safe-bottom);
}

.btn {
  min-height: 44px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
}

.btn-primary {
  flex: 2 1 0;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  padding: 12px;
}

.btn-primary:active {
  background: var(--primary-active);
}

.btn-primary:disabled {
  opacity: 0.6;
}

.btn-secondary {
  flex: 1 1 0;
  background: var(--secondary);
  color: var(--secondary-text);
  padding: 10px;
}

.btn-secondary:active {
  background: var(--border);
}

/* ---------- Dialogs ---------- */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.dialog {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dialog p {
  margin: 0;
  font-size: 18px;
}

.dialog-buttons {
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.dialog-buttons .btn {
  flex: 1 1 0;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 27, 25, 0.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  opacity: 1;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}

.toast.fade {
  opacity: 0;
}

@media (min-width: 700px) {
  .login-form,
  .work-area {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
  }

  .source-block {
    font-size: 24px;
  }
}
