:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f1e8;
  color: #182726;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-height: 100vh; margin: 0; background: #f4f1e8; }
button, input { font: inherit; }
button { min-height: 44px; border: 1px solid #183b3a; border-radius: 8px; background: #183b3a; color: #fff; font-weight: 800; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
h1, h2, p { margin: 0; }

.shell { min-height: 100vh; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.login__form { width: min(430px, 100%); display: grid; gap: 14px; padding: 22px; border: 1px solid #d8d1c1; border-radius: 8px; background: #fffdf8; box-shadow: 0 20px 60px rgba(24, 39, 38, .14); }
.login__form label { display: grid; gap: 7px; color: #4b5a56; font-weight: 800; }
input { width: 100%; border: 1px solid #cfc6b4; border-radius: 8px; padding: 12px; background: #fff; color: #182726; }

.app { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: max(16px, env(safe-area-inset-top)) 18px 14px; background: #fffdf8; border-bottom: 1px solid #ded6c6; }
.topbar h1 { font-size: 22px; }
.eyebrow { color: #2c766d; font-size: 12px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.ghost, .icon-button { background: #fffdf8; color: #183b3a; border-color: #cfc6b4; }
.icon-button { width: 44px; padding: 0; font-size: 28px; line-height: 1; display: grid; place-items: center; }

.home-actions { width: min(760px, calc(100vw - 28px)); margin: 0 auto; padding: 24px 0 42px; display: grid; gap: 14px; align-content: center; }
.primary-action { width: 100%; min-height: 168px; display: grid; align-content: center; justify-items: start; gap: 7px; padding: 24px; text-align: left; border: 0; border-radius: 8px; background: #183b3a; color: #fff; box-shadow: 0 18px 44px rgba(24, 59, 58, .18); }
.primary-action span { font-size: clamp(32px, 9vw, 58px); line-height: 1; }
.primary-action small { color: #dfece8; font-size: 15px; font-weight: 700; }
.primary-action.secondary { background: #d99d43; color: #21190d; box-shadow: 0 18px 44px rgba(140, 91, 21, .18); }
.primary-action.secondary small { color: #443016; }

.capture-panel, .archive, .detail { width: min(860px, calc(100vw - 28px)); margin: 0 auto; padding: 18px 0 48px; display: grid; gap: 16px; align-content: start; }
.panel-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.panel-head h2 { font-size: 22px; }
.capture-input { display: grid; gap: 8px; padding: 22px; border: 1px dashed #b9ae9b; border-radius: 8px; background: #fffdf8; color: #183b3a; font-weight: 900; text-align: center; }
.capture-input input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; pointer-events: none; }
.capture-input span { font-size: 22px; }
.capture-input small { color: #65716d; font-weight: 700; }
.selected-files { display: grid; gap: 8px; }
.file-pill { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid #ded6c6; border-radius: 8px; background: #fffdf8; color: #4b5a56; font-weight: 700; }
.message { min-height: 20px; color: #a33a2d; line-height: 1.4; }
.message.neutral { color: #4b5a56; font-weight: 700; }

.archive-groups { display: grid; gap: 18px; }
.group { display: grid; gap: 10px; }
.group h3 { margin: 0; font-size: 14px; color: #4b5a56; text-transform: uppercase; }
.capture-stack { position: relative; min-height: 120px; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.capture-stack::before, .capture-stack::after { content: ""; position: absolute; inset: 14px 10px auto 10px; height: 92px; border: 1px solid #ded6c6; border-radius: 8px; background: #fff8ec; transform: rotate(-2deg); }
.capture-stack::after { inset: 7px 5px auto 18px; background: #f8efe0; transform: rotate(2deg); }
.capture-stack__front { position: relative; z-index: 1; min-height: 112px; display: grid; gap: 8px; padding: 16px; border: 1px solid #d7cbb8; border-radius: 8px; background: #fffdf8; box-shadow: 0 12px 32px rgba(36, 43, 37, .1); }
.capture-stack strong { font-size: 18px; color: #182726; }
.capture-stack span { color: #596964; font-size: 14px; }
.capture-strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(78%, 1fr); gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 4px 10px; }
.capture-card { scroll-snap-align: start; min-height: 150px; display: grid; align-content: space-between; gap: 14px; padding: 16px; border: 1px solid #d7cbb8; border-radius: 8px; background: #fffdf8; color: #182726; text-align: left; }
.capture-card strong { font-size: 18px; overflow-wrap: anywhere; }
.capture-card small { color: #5e6b67; font-weight: 700; }
.status-chip { justify-self: start; padding: 5px 8px; border-radius: 999px; background: #e8f1ee; color: #1f5f57; font-size: 12px; font-weight: 900; }
.status-chip[data-status="failed"] { background: #f7dedb; color: #9d3429; }

.word-list { display: grid; gap: 10px; }
.word-card { display: grid; gap: 12px; padding: 16px; border: 1px solid #ded6c6; border-radius: 8px; background: #fffdf8; }
.word-main { display: grid; gap: 4px; }
.arabic { direction: rtl; font-size: 34px; line-height: 1.2; font-family: "Geeza Pro", "Noto Naskh Arabic", serif; }
.din { color: #1f5f57; font-weight: 900; }
.translation { color: #394744; font-weight: 700; }
.word-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.word-actions button { background: #fffdf8; color: #183b3a; border-color: #cfc6b4; }

.explain-dialog { width: min(620px, calc(100vw - 28px)); max-height: min(82vh, 720px); padding: 0; border: 0; border-radius: 8px; background: #fffdf8; color: #182726; box-shadow: 0 26px 90px rgba(24, 39, 38, .28); }
.explain-dialog::backdrop { background: rgba(24, 39, 38, .38); }
.dialog-panel { display: grid; gap: 16px; padding: 18px; }
.explain-body { max-height: 58vh; overflow: auto; color: #273936; line-height: 1.55; white-space: pre-wrap; }
.toast { position: fixed; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 4; padding: 13px 14px; border-radius: 8px; background: #183b3a; color: #fff; box-shadow: 0 18px 50px rgba(24, 39, 38, .24); font-weight: 800; }

@media (min-width: 720px) {
  .home-actions { grid-template-columns: 1fr 1fr; }
  .capture-strip { grid-auto-columns: minmax(320px, 42%); }
  .word-actions { grid-template-columns: 160px 180px; justify-content: start; }
}
