/* ============================================================
   Doodle World — application styles
   Brand palette from branding.config.json (Standard Edition).
   RTL-safe: logical properties everywhere; html[dir=rtl] flips
   only what logical CSS cannot express.
   ============================================================ */

@font-face {
  font-family: 'Baloo 2';
  src: url('assets/fonts/baloo2-latin-var.woff2') format('woff2-variations');
  font-weight: 400 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Baloo Bhaijaan 2';
  src: url('assets/fonts/baloo-bhaijaan2-arabic-var.woff2') format('woff2-variations');
  font-weight: 400 800;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-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;
}

:root {
  --c-primary: #5B5FE9;
  --c-primary-deep: #474BC9;
  --c-accent: #FF6B6B;
  --c-sunny: #FFC93C;
  --c-teal: #2EC4B6;
  --c-ink: #1F2937;
  --c-paper: #FFFDF7;
  --c-deep: #2B2158;
  --c-muted: #6B7280;
  --c-line: #E7E3DA;
  --c-success: #2FA96C;
  --c-warn: #E9A23B;
  --c-danger: #E5484D;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(43, 33, 88, 0.10);
  --shadow-sm: 0 4px 14px rgba(43, 33, 88, 0.08);
  --font-latin: 'Baloo 2';
  --font-arabic: 'Baloo Bhaijaan 2';
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-latin), 'Nunito', 'Segoe UI', system-ui, sans-serif;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(91, 95, 233, 0.08), transparent 60%),
    radial-gradient(900px 420px at -10% 20%, rgba(255, 201, 60, 0.10), transparent 55%),
    var(--c-paper);
  color: var(--c-ink);
  min-height: 100vh;
}
body.lang-ar { font-family: var(--font-arabic), 'Baloo 2', 'Nunito', system-ui, sans-serif; }

.icon { vertical-align: -0.2em; }

/* ---------- Boot splash ---------- */
.boot-splash { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 18px; }
.boot-logo {
  width: 84px; height: 84px; border-radius: 24px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  position: relative;
  animation: bootPulse 1.4s ease-in-out infinite;
}
.boot-logo::after {
  content: ''; position: absolute; inset: 20px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, #ffd97a 60%, var(--c-sunny));
}
.boot-text { color: var(--c-muted); font-size: 18px; }
@keyframes bootPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.boot-error { padding: 60px; text-align: center; color: var(--c-danger); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: none; border-radius: 999px;
  padding: 11px 22px; font-size: 16px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  min-height: 44px;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--c-primary-deep); }
.btn-secondary { background: color-mix(in srgb, var(--c-primary) 10%, white); color: var(--c-primary-deep); border: 1.5px solid color-mix(in srgb, var(--c-primary) 35%, white); }
.btn-secondary:hover { background: color-mix(in srgb, var(--c-primary) 16%, white); }
.btn-ghost { background: transparent; color: var(--c-ink); border: 1.5px solid var(--c-line); }
.btn-ghost:hover { background: #fff; }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-sm { padding: 8px 16px; font-size: 14px; min-height: 40px; }
.btn-icon { padding: 8px; min-height: 36px; min-width: 36px; }
.btn-chip { padding: 7px 16px; min-height: 38px; font-size: 14px; background: #fff; border: 1.5px solid var(--c-line); color: var(--c-ink); }
.btn-chip.active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.btn-col .btn { justify-content: center; }
.flex-fill { flex: 1; }

.input, select.input {
  font-family: inherit; font-size: 15px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--c-line); background: #fff; color: var(--c-ink);
  min-height: 44px;
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--c-primary) 45%, white); border-color: var(--c-primary); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600;
  background: #fff; border: 1.5px solid var(--c-line); color: var(--c-muted);
}
.chip-success { background: color-mix(in srgb, var(--c-success) 10%, white); border-color: color-mix(in srgb, var(--c-success) 40%, white); color: var(--c-success); }
.chip-warn { background: color-mix(in srgb, var(--c-warn) 12%, white); border-color: color-mix(in srgb, var(--c-warn) 45%, white); color: #a16c12; }
.chip-error { background: color-mix(in srgb, var(--c-danger) 10%, white); border-color: color-mix(in srgb, var(--c-danger) 40%, white); color: var(--c-danger); }

/* ---------- Dashboard ---------- */
.app-root { max-width: 1180px; margin-inline: auto; padding: 22px clamp(14px, 3vw, 34px) 40px; }
.dash-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding-block: 8px 18px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 54px; height: 54px; border-radius: 14px; box-shadow: var(--shadow-sm); }
.brand-name { margin: 0; font-size: 26px; line-height: 1.1; color: var(--c-deep); }
.brand-sub { color: var(--c-muted); font-size: 13px; }
.dash-header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lang-toggle { display: inline-flex; gap: 6px; }
.dash-strip { display: flex; gap: 10px; flex-wrap: wrap; padding-block: 4px 18px; }
.dash-section { margin-top: 8px; }
.section-title { font-size: 21px; color: var(--c-deep); margin: 4px 0 16px; }

.world-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}
.world-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow: hidden; cursor: pointer; transition: transform 0.18s ease, box-shadow 0.18s ease;
  border: 2.5px solid transparent;
}
.world-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.world-card.selected { border-color: var(--c-primary); }
.world-card:focus-visible { outline: 3px solid color-mix(in srgb, var(--c-primary) 50%, white); }
.world-thumb { position: relative; aspect-ratio: 16/10; background: linear-gradient(135deg, #cfe6ff, #e8d9ff); }
.world-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.world-thumb.fallback { background: linear-gradient(135deg, #a8e0ff, #c3a6ff); }
.wf-underwater-adventure.fallback { background: linear-gradient(135deg, #12628c, #2ec4b6); }
.wf-outer-space.fallback { background: linear-gradient(135deg, #0b0d2a, #5b5fe9); }
.wf-magical-garden.fallback { background: linear-gradient(135deg, #7ec850, #ffc93c); }
.wf-enchanted-forest.fallback { background: linear-gradient(135deg, #1c2b3a, #54d8c9); }
.world-badge {
  position: absolute; inset-inline-start: 10px; inset-block-start: 10px;
  background: var(--c-sunny); color: var(--c-deep);
  font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 999px;
}
.world-badge:empty { display: none; }
.world-body { padding: 16px 18px 18px; }
.world-body h3 { margin: 0 0 6px; font-size: 18px; color: var(--c-deep); }
.world-body p { margin: 0 0 14px; color: var(--c-muted); font-size: 14px; min-height: 40px; }
.empty-note { color: var(--c-muted); padding: 30px; text-align: center; }
.dash-footer {
  margin-top: 40px; padding-block: 16px; border-top: 1.5px solid var(--c-line);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--c-muted); font-size: 13px;
}

/* ---------- Session ---------- */
.session-layout {
  display: grid; grid-template-columns: 1fr minmax(300px, 360px);
  gap: 18px; align-items: start;
}
.world-stage {
  position: relative; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 10; background: #0b0d2a; box-shadow: var(--shadow);
  min-height: 420px;
}
.world-canvas { width: 100% !important; height: 100% !important; display: block; }
.session-panel { display: flex; flex-direction: column; gap: 14px; }
.panel-card {
  background: #fff; border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 10px;
}
.panel-label { font-size: 13px; font-weight: 700; color: var(--c-muted); letter-spacing: 0.02em; }
.camera-frame { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: #10131a; aspect-ratio: 4/3; }
.camera-preview { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.status-hint { text-align: center; }
.status-pill {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px; border-radius: 999px;
  background: color-mix(in srgb, var(--c-primary) 8%, white);
  color: var(--c-deep); font-weight: 700; font-size: 14.5px;
  border: 1.5px solid color-mix(in srgb, var(--c-primary) 22%, white);
}
.status-pill.busy { animation: pillPulse 1.6s ease-in-out infinite; }
.status-pill.success { background: color-mix(in srgb, var(--c-success) 12%, white); border-color: color-mix(in srgb, var(--c-success) 45%, white); color: var(--c-success); }
.status-pill.error { background: color-mix(in srgb, var(--c-danger) 10%, white); border-color: color-mix(in srgb, var(--c-danger) 45%, white); color: var(--c-danger); }
@keyframes pillPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.72; } }
.name-card .name-row { display: flex; gap: 8px; }
.name-input { flex: 1; }
.name-note { margin: 0; font-size: 12.5px; color: var(--c-muted); }
.name-wrap.confirmed .name-input { border-color: var(--c-success); }
.char-counter {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  font-weight: 700; color: var(--c-deep); font-size: 15px;
  background: var(--c-paper); border-radius: var(--radius-sm); padding: 10px;
}
.actions-card .btn { width: 100%; }
.hidden { display: none !important; }

/* ---------- Settings / modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(31, 25, 60, 0.45);
  display: grid; place-items: center; padding: 20px; z-index: 90;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--c-paper); border-radius: 20px; max-width: 520px; width: 100%;
  max-height: 88vh; overflow: auto; box-shadow: 0 24px 60px rgba(20, 14, 50, 0.35);
  padding: 22px;
}
.modal-wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h2 { margin: 0; font-size: 22px; color: var(--c-deep); }
.settings-body { display: flex; flex-direction: column; gap: 6px; }
.settings-fieldset { border: 1.5px solid var(--c-line); border-radius: var(--radius-sm); padding: 14px 16px 16px; margin: 0 0 14px; }
.settings-fieldset legend { font-weight: 700; color: var(--c-deep); padding-inline: 8px; font-size: 15px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-block: 7px; }
.settings-label { color: var(--c-ink); font-size: 14.5px; }
.slider-row { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.slider { flex: 1; accent-color: var(--c-primary); }
.slider-value { font-weight: 700; color: var(--c-primary-deep); min-width: 52px; text-align: end; font-size: 14px; }
.check-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14.5px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--c-primary); }
.storage-line { color: var(--c-muted); font-size: 14px; }
.muted { color: var(--c-muted); font-size: 14px; }
.lock-note { display: inline-flex; align-items: center; gap: 6px; color: var(--c-teal); font-weight: 600; }
.privacy { max-width: 480px; }
.confirm-body { padding: 6px 2px 2px; }

/* ---------- Editor ---------- */
.editor-body { display: flex; flex-direction: column; gap: 12px; }
.editor-hint { margin: 0; color: var(--c-muted); font-size: 14px; }
.editor-stage {
  background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 0 / 22px 22px;
  border-radius: var(--radius-sm); overflow: hidden; height: 340px;
}
.editor-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.editor-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--c-line);
  background: #fff; cursor: pointer; color: var(--c-ink);
}
.tool-btn:hover { border-color: var(--c-primary); color: var(--c-primary); }
.tool-btn.active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.brush-row { display: flex; align-items: center; gap: 12px; }
.editor-actions { justify-content: flex-end; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed; inset-block-end: 18px; inset-inline-end: 18px;
  display: flex; flex-direction: column; gap: 10px; z-index: 120; max-width: min(420px, 92vw);
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--c-deep); color: #fff; border-radius: 14px;
  padding: 12px 16px; font-size: 14.5px; box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(8px); transition: all 0.3s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast-success { background: var(--c-success); }
.toast-warn { background: #b97a10; }
.toast-error { background: var(--c-danger); }

/* ---------- RTL ---------- */
html[dir='rtl'] body { font-family: var(--font-arabic), 'Baloo 2', system-ui, sans-serif; }
html[dir='rtl'] .brand-name { letter-spacing: 0; }
.slider-value { direction: ltr; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .session-layout { grid-template-columns: 1fr; }
  .world-stage { min-height: 300px; }
}
@media (max-width: 560px) {
  .brand-name { font-size: 21px; }
  .world-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .world-body p { min-height: 0; }
  .app-root { padding-inline: 12px; }
}
@media (max-width: 400px) {
  .world-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Session: full-screen world ---------- */
body.in-session { overflow: hidden; background: #0b0d2a; }
body.in-session .app-root { max-width: none; margin: 0; padding: 0; }
body.in-session .session-layout { position: fixed; inset: 0; display: block; }
body.in-session .world-stage {
  position: absolute; inset: 0; width: 100%; height: 100%;
  aspect-ratio: auto; min-height: 0; border-radius: 0; box-shadow: none;
}
body.in-session .session-toolbar {
  position: absolute; inset-block-start: 14px; inset-inline-start: 14px;
  display: flex; gap: 8px; z-index: 30;
}
body.in-session .session-panel {
  position: absolute; inset-block-end: 14px; inset-inline-end: 14px;
  width: min(330px, calc(100vw - 28px)); max-height: calc(100dvh - 28px);
  overflow-y: auto; z-index: 20;
  transition: opacity .2s ease, transform .2s ease;
}
body.in-session .session-panel .panel-card { background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(6px); }
body.in-session .session-panel.collapsed {
  opacity: 0; pointer-events: none; transform: translateY(12px) scale(.96);
}
@media (max-width: 960px) {
  body.in-session .world-stage { min-height: 0; }
}
