/* ===== EduGUI design system: clean editorial + soft depth ===== */
:root {
  --font-ar: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-head: 'Cairo', var(--font-ar);
  /* light theme */
  --bg: #f7f8fb;        --surface: #ffffff;   --surface-2: #f0f2f7;
  --text: #18203a;      --text-soft: #5a647e;  --border: #e6e9f2;
  --accent-1: #16b5a4;  --accent-2: #6d5ef0;   /* teal → violet */
  --good: #1aa86b;      --warn: #e0a106;       --bad: #e0524d;
  --radius: 16px;       --shadow: 0 6px 24px -12px rgba(24,32,58,.25);
  --gap: 16px;
}
:root[data-theme='dark'] {
  --bg: #0e1220;        --surface: #161b2e;    --surface-2: #1e2440;
  --text: #eef1fa;      --text-soft: #9aa3c0;  --border: #283050;
  --shadow: 0 8px 30px -14px rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ar); background: var(--bg); color: var(--text);
  font-size: 17px; line-height: 1.7;
}
.accent-text {
  background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* App grid: header + (canvas 9 / chat 3). Uses logical columns → flips with dir. */
.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.header {
  display: flex; align-items: center; gap: var(--gap);
  padding: 10px 20px; border-block-end: 1px solid var(--border);
  background: var(--surface);
}
.header h1 { font-family: var(--font-head); font-size: 1.15rem; margin: 0; }
.header .spacer { flex: 1; }
.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 6px 14px; transition: transform .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.main { display: grid; grid-template-columns: 9fr 3fr; gap: var(--gap); padding: var(--gap); min-height: 0; }

/* Tablet / mobile: stack canvas (top) over chat (bottom), each with a workable height. */
@media (max-width: 900px) {
  body { font-size: 16px; }
  .header { flex-wrap: wrap; row-gap: 6px; padding: 10px 14px; }
  .header h1 { font-size: 1rem; flex-basis: 100%; }
  .main { grid-template-columns: 1fr; grid-template-rows: 58vh 1fr; }
  .btn { min-height: 40px; } /* comfortable touch targets */
}

.canvas, .chat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-height: 0; display: flex; flex-direction: column; overflow: hidden;
}
.canvas { padding: 0; }
.canvas .empty {
  margin: auto; max-width: 26ch; text-align: center; color: var(--text-soft);
  padding: 24px;
}
.canvas iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Chat */
.chat .log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 90%; padding: 10px 14px; border-radius: 14px; }
.bubble.user { align-self: start; background: var(--surface-2); }
.bubble.bot  { align-self: end; background: linear-gradient(135deg, color-mix(in srgb, var(--accent-1) 14%, var(--surface)), color-mix(in srgb, var(--accent-2) 14%, var(--surface))); }
.chat form { display: flex; gap: 8px; padding: 12px; border-block-start: 1px solid var(--border); }
.chat input {
  flex: 1; font: inherit; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  text-align: start;
}
.chat input:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }

/* Mastery chip in header */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--text-soft); }
.chip.badge-gifted { color: var(--accent, #2f6f6a); font-weight: 600; }
.chip.badge-advanced { color: var(--accent, #2f6f6a); }
.chip.badge-typical { color: var(--text-soft); }
.btn.active { color: var(--accent, #2f6f6a); border-color: var(--accent, #2f6f6a); }

/* Celebration toast (anchored bottom-center, theme-aware) */
#toast {
  position: fixed; inset-block-end: 24px; inset-inline-start: 50%; transform: translate(-50%, 16px);
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2)); color: #fff;
  font-family: var(--font-head); padding: 10px 20px; border-radius: 999px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .3s ease, transform .3s ease;
  z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Consent gate (R3) */
.overlay { position: fixed; inset: 0; background: rgba(10,14,28,.55); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 100; padding: 20px; }
/* The `hidden` attribute must win over `.overlay`'s display (author rule beats the UA [hidden] rule). */
.overlay[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 460px; padding: 26px; }
.modal h2 { font-family: var(--font-head); margin: 0 0 .4em; }
.modal p { color: var(--text-soft); }
.ages { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 16px 0; display: grid; gap: 8px; }
.ages legend { padding: 0 6px; color: var(--text-soft); font-size: .85rem; }
.ages label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.btn.primary { background: linear-gradient(135deg, var(--accent-1), var(--accent-2)); color: #fff;
  border: none; width: 100%; padding: 12px; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  #toast { transition: opacity .2s ease !important; }
}
