/* Local fonts — no CDN at runtime */
@font-face {
  font-family: 'Noto Sans Arabic';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('./assets/NotoSansArabic-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 Sans Arabic';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('./assets/NotoSansArabic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Drawing-office palette: paper, ink, one rule colour, one green accent. */
:root {
  --paper: #efece6;
  --paper-2: #f3f1eb;
  --ink: #2b2b29;
  --ink-2: #5f5d58;
  --rule: #c9c4b8;
  --accent: #8f1622;
  --accent-ink: #ffffff;
  --font: 'Noto Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  --panel-w: 300px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

/* ---- keyboard focus: always visible ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.skip-link {
  position: absolute;
  inset-inline-start: 8px;
  top: -40px;
  padding: 4px 10px;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--ink);
  z-index: 10;
}
.skip-link:focus { top: 8px; }

/* ---- layout ---- */
#layout {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;   /* column 1 is the inline-start side: the right in RTL */
  height: 100vh;
  height: 100dvh;
}
#panel { grid-column: 1; grid-row: 1; }
#viewport { grid-column: 2; grid-row: 1; position: relative; min-width: 0; min-height: 0; }
[hidden] { display: none !important; }
#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline-offset: -3px;
}
.webgl-error {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

/* ---- panel ---- */
#panel {
  background: var(--paper-2);
  border-inline-start: 1px solid var(--rule);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 8px;
}
h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 12.5px; }
.sheet-toggle { display: none; }

section, .presets { padding: 10px 16px; }
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--rule);
}

/* ---- buttons ---- */
button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 5px 12px;
  cursor: pointer;
  min-height: 34px;
}
button:hover { background: var(--paper); }
button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- select ---- */
.select-row { display: flex; align-items: center; gap: 10px; }
.select-row span { flex: none; }
select {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 5px 8px;
  min-height: 34px;
  flex: 1 1 auto;
  min-width: 0;
}

/* ---- range slider ---- */
.range-row { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.range-row span { flex: none; }
.range-row output { flex: none; min-width: 3.2em; text-align: center; font-variant-numeric: tabular-nums; }
input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--accent);
  margin: 0;
  height: 24px;
}

/* ---- checkboxes ---- */
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { margin: 2px 0; }
.checks label { display: flex; align-items: center; gap: 8px; min-height: 30px; cursor: pointer; }
input[type="checkbox"] {
  width: 16px; height: 16px; margin: 0;
  accent-color: var(--accent);
}

.hint { margin: 6px 0 0; color: var(--ink-2); font-size: 12.5px; }
.door-row { margin-top: 10px; }

/* ---- colour key ---- */
.key { list-style: none; margin: 0; padding: 0; }
.key li { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.swatch {
  flex: none;
  width: 22px; height: 14px;
  border: 1px solid var(--rule);
}

/* ---- specs table ---- */
.specs { border-collapse: collapse; width: 100%; font-size: 13px; }
.specs th, .specs td {
  text-align: start;
  vertical-align: top;
  padding: 5px 0;
  border-bottom: 1px solid var(--rule);
}
.specs th { font-weight: 600; white-space: nowrap; padding-inline-end: 10px; width: 1%; }

/* ---- actions + footer ---- */
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status { color: var(--accent); font-size: 13px; min-height: 1.6em; }
.panel-foot {
  margin-top: auto;
  padding: 10px 16px 16px;
  color: var(--ink-2);
  font-size: 12px;
  border-top: 1px solid var(--rule);
}
.panel-foot p { margin: 0; }

/* ---- mobile: panel becomes a bottom sheet ---- */
@media (max-width: 720px) {
  :root { --panel-w: 0px; }
  #layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  #viewport { grid-column: 1; grid-row: 1; }
  #panel {
    grid-column: 1;
    grid-row: 2;
    border-inline-start: 0;
    border-top: 1px solid var(--rule);
    max-height: 70vh;
    max-height: 70dvh;
  }
  .panel-head { padding: 10px 12px 4px; align-items: center; }
  h1 { font-size: 16px; }
  .sub { display: none; }
  .sheet-toggle { display: inline-block; flex: none; }
  .sheet-toggle[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .presets { padding: 4px 12px 10px; }
  .presets .section-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; margin: 0; padding: 0; }
  .btn-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 3px 2px;     /* keep focus rings visible inside the scroller */
    scrollbar-width: thin;
  }
  .btn-row .preset { flex: none; white-space: nowrap; }
  .panel-body { display: none; }
  .panel-body.open { display: block; }
  section { padding: 8px 12px; }
  .panel-foot { padding: 8px 12px 14px; }
}

/* very narrow phones (360px) */
@media (max-width: 400px) {
  body { font-size: 13.5px; }
  button { padding: 5px 10px; }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 120ms linear, color 120ms linear; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
