/* Interface styling. It follows the NOOR design system (see reference/noor-design.md):
   Nunito, soft surfaces with 2px borders and hard offset shadows, pressable 3D buttons.
   The blocks themselves take their colours from the catalogue, not from here. */

@font-face {
  font-family: Nunito;
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url(../assets/fonts/Nunito-latin.woff2) format('woff2');
}

:root {
  --noor-primary: #03a9f4;
  --noor-primary-light: #81d4fa;
  --noor-primary-dark: #0277bd;
  --noor-secondary: #ffc107;
  --noor-secondary-light: #ffe082;
  --noor-secondary-dark: #ff8f00;
  --noor-tertiary: #f78a8b;
  --noor-tertiary-dark: #da6769;
  --noor-quaternary: #bd90fc;
  --noor-quaternary-dark: #885cc6;
  --noor-teal: #00cd9d;
  --noor-teal-light: #5ce0c2;
  --noor-teal-dark: #009673;
  --noor-text: #424242;
  --noor-text-soft: #757575;
  --noor-text-faint: #9e9e9e;
  --noor-surface: #fff;
  --noor-surface-variant: #f5f5f5;
  --noor-surface-container: #fafafa;
  --noor-divider: #e0e0e0;
  --noor-shadow-card: 3px 3px 0 rgba(0, 0, 0, 0.06);
  --radius-md: 12px;
  --radius-lg: 16px;
  --font: Nunito, 'Noto Kufi Arabic', 'Noto Sans Arabic', 'Geeza Pro', 'Segoe UI', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--noor-text);
  background: linear-gradient(135deg, #f0fdf9, #fff 50%, #f0f9ff);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

[hidden] {
  display: none !important;
}

.sr-only,
.sprite {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.app {
  display: grid;
  grid-template: 'bar' auto 'table' 1fr 'tray' auto / minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Top bar ---------- */

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
  background: var(--noor-surface);
  border-bottom: 2px solid var(--noor-surface-variant);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: none;
  object-fit: cover;
  border: 2px solid var(--noor-surface-variant);
  border-radius: var(--radius-md);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.06);
}

.brand-name {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stars {
  display: flex;
  gap: 2px;
  margin-inline-start: auto;
  padding: 4px 10px;
  background: #fff8e1;
  border: 2px solid var(--noor-secondary-light);
  border-radius: 999px;
  box-shadow: 0 2px 0 var(--noor-secondary-light);
}

.star {
  display: flex;
  width: 22px;
  height: 22px;
}

.star svg {
  width: 100%;
  height: 100%;
  fill: #fff;
  stroke: var(--noor-secondary-light);
  stroke-width: 2;
  stroke-linejoin: round;
  transition: fill 0.2s, stroke 0.2s, transform 0.35s cubic-bezier(0.34, 1.7, 0.5, 1);
}

.star.is-lit svg {
  fill: var(--noor-secondary);
  stroke: var(--noor-secondary-dark);
  transform: scale(1.15) rotate(-8deg);
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn,
.pill-btn {
  --depth: 4px;
  --face: var(--noor-primary);
  --edge: var(--noor-primary-dark);
  --ink: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  min-width: 44px;
  margin-bottom: var(--depth);
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--face);
  color: var(--ink);
  box-shadow: 0 var(--depth) 0 var(--edge);
  font: 800 15px var(--font);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out, opacity 0.2s;
}

.icon-btn:active,
.pill-btn:active {
  transform: translateY(var(--depth));
  box-shadow: none;
}

.icon-btn:focus-visible,
.pill-btn:focus-visible {
  outline: 3px solid var(--face);
  outline-offset: 3px;
}

.icon-btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn--secondary {
  --face: var(--noor-secondary);
  --edge: var(--noor-secondary-dark);
  --ink: var(--noor-text);
}

.icon-btn--tertiary {
  --face: var(--noor-tertiary);
  --edge: var(--noor-tertiary-dark);
}

.pill-btn {
  --face: var(--noor-quaternary);
  --edge: var(--noor-quaternary-dark);
  padding: 0 16px;
}

#sound[aria-pressed='true'] .when-off,
#sound[aria-pressed='false'] .when-on {
  display: none;
}

#sound[aria-pressed='false'] {
  --face: #fff;
  --edge: var(--noor-divider);
  --ink: var(--noor-text-faint);
  outline: 2px solid var(--noor-surface-variant);
  outline-offset: -2px;
}

/* ---------- The table ---------- */

.table {
  grid-area: table;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

.scenery {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.float {
  position: absolute;
  width: 34px;
  height: 34px;
  opacity: 0.55;
  animation: noor-float 5s ease-in-out infinite;
}

.f1 { top: 10%; left: 7%; fill: var(--noor-secondary-light); }
.f2 { top: 16%; right: 9%; fill: var(--noor-primary-light); animation-delay: -1.3s; width: 40px; height: 40px; }
.f3 { bottom: 14%; left: 12%; fill: #c69eff; animation-delay: -2.4s; width: 22px; height: 22px; }
.f4 { bottom: 20%; right: 14%; fill: var(--noor-teal-light); animation-delay: -3.1s; width: 26px; height: 26px; }
.f5 { top: 46%; left: 3%; fill: #fe9b9d; animation-delay: -0.6s; width: 20px; height: 20px; }

@keyframes noor-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.hint {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 10px;
  padding: 6px 14px 6px 6px;
  padding-inline: 6px 14px;
  background: var(--noor-surface);
  border: 2px solid var(--noor-primary-light);
  border-radius: var(--radius-lg);
  box-shadow: 3px 3px 0 var(--noor-primary);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  pointer-events: none;
  animation: hint-in 0.35s cubic-bezier(0.34, 1.7, 0.5, 1);
}

.hint svg {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 5px;
  border-radius: 10px;
  background: var(--noor-primary);
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes hint-in {
  from { opacity: 0; transform: translateY(8px) scale(0.9); }
}

/* ---------- Blocks ---------- */

.piece,
.tray-block {
  cursor: grab;
  outline: none;
}

.piece-inner,
.block-disc,
.carrier-tilt {
  transform-box: fill-box;
  transform-origin: center;
}

.block-top {
  fill: var(--block);
}

.block-side {
  fill: color-mix(in srgb, var(--block) 70%, #000);
}

.block-gloss,
.block-window-edge {
  pointer-events: none;
}

.block-window-edge {
  fill: none;
  stroke: rgba(0, 0, 0, 0.14);
  stroke-width: 0.4;
}

.piece:focus-visible .block-top,
.tray-block:focus-visible .block-top {
  stroke: var(--noor-text);
  stroke-width: 1.6;
  stroke-dasharray: 4 2.5;
}

.is-loose .piece-inner {
  animation: wobble 3.6s ease-in-out infinite;
}

.piece:nth-child(2n) .piece-inner { animation-delay: -1.1s; }
.piece:nth-child(3n) .piece-inner { animation-delay: -2.3s; }

@keyframes wobble {
  0%, 100% { transform: rotate(-1.3deg); }
  50% { transform: rotate(1.3deg); }
}

.ghost {
  fill: color-mix(in srgb, var(--block) 22%, transparent);
  stroke: var(--block);
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
  stroke-linecap: round;
  animation: ghost 0.9s ease-in-out infinite alternate;
}

@keyframes ghost {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

.spark {
  pointer-events: none;
}

.carry,
.confetti-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.carrier-tilt {
  transform: scale(1.07) rotate(-2deg);
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.22));
}

.carrier .piece-inner {
  animation: none;
}

.confetti {
  position: absolute;
  top: 0;
  left: 0;
  width: 10px;
  height: 14px;
  border-radius: 3px;
}

/* ---------- The tray ---------- */

.tray {
  grid-area: tray;
  position: relative;
  padding: 10px calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: var(--noor-surface);
  border-top: 2px solid var(--noor-surface-variant);
  touch-action: none;
  z-index: 1;
}

.tray-rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  max-width: 560px;
  margin: 0 auto;
  /* The blocks keep their left-to-right build in both languages. */
  direction: ltr;
}

.tray-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 3px;
  font-size: 12px;
  font-weight: 800;
  color: var(--noor-text-soft);
  white-space: nowrap;
}

[dir='rtl'] .tray-label {
  direction: rtl;
}

.tray-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--block);
}

.tray-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tray-check {
  display: flex;
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--noor-teal);
  box-shadow: 0 2px 0 var(--noor-teal-dark);
  transform: scale(0);
  transition: transform 0.3s cubic-bezier(0.34, 1.7, 0.5, 1);
}

.tray-row.is-complete .tray-check {
  transform: scale(1);
}

.tray-check svg {
  width: 100%;
  height: 100%;
  padding: 3px;
  fill: none;
  stroke: #fff;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tray-blocks {
  display: block;
  width: 100%;
  overflow: visible;
}

.tray-bin {
  position: absolute;
  inset: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px;
  border: 3px dashed var(--noor-primary-light);
  border-radius: var(--radius-lg);
  background: rgba(225, 245, 254, 0.94);
  color: var(--noor-primary-dark);
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 1;
}

.tray-bin svg {
  flex: none;
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tray.is-bin .tray-bin {
  opacity: 1;
}

/* ---------- Celebration ---------- */

.cheer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14px;
  pointer-events: none;
}

.cheer-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 24px 14px;
  background: var(--noor-surface);
  border: 2px solid var(--noor-secondary-light);
  border-radius: 20px;
  box-shadow: 4px 4px 0 var(--noor-secondary);
  font-size: 15px;
  font-weight: 700;
  color: var(--noor-text-soft);
  animation: cheer-in 0.5s cubic-bezier(0.34, 1.7, 0.5, 1);
}

.cheer-card strong {
  font-size: 26px;
  font-weight: 900;
  color: var(--noor-text);
}

.cheer-stars {
  display: flex;
  gap: 4px;
}

.cheer-stars svg {
  width: 30px;
  height: 30px;
  fill: var(--noor-secondary);
  stroke: var(--noor-secondary-dark);
  stroke-width: 1.5;
  stroke-linejoin: round;
  animation: noor-float 1.2s ease-in-out infinite;
}

.cheer-stars svg:nth-child(2) { width: 40px; height: 40px; animation-delay: -0.4s; }
.cheer-stars svg:nth-child(3) { animation-delay: -0.8s; }

@keyframes cheer-in {
  from { opacity: 0; transform: translateY(-20px) scale(0.7); }
}

.load-error {
  position: fixed;
  inset: auto 16px 40% 16px;
  margin: 0;
  padding: 16px;
  background: var(--noor-surface);
  border: 2px solid #fe9b9d;
  border-radius: var(--radius-lg);
  box-shadow: 3px 3px 0 var(--noor-tertiary);
  font-weight: 800;
  text-align: center;
}

/* ---------- Other shapes of screen ---------- */

/* Narrow phones: the name gives way to the buttons. */
@media (max-width: 479px) {
  .brand-name { display: none; }
  .brand-mark { width: clamp(30px, 9vw, 40px); height: clamp(30px, 9vw, 40px); }
  .bar { gap: 8px; padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }
  .bar-actions { gap: 6px; }
  .icon-btn, .pill-btn { height: clamp(38px, 11vw, 44px); min-width: clamp(38px, 11vw, 44px); }
  .pill-btn { padding: 0 12px; }
  .stars { padding: 4px 8px; }
  .star { width: clamp(15px, 4.4vw, 22px); height: clamp(15px, 4.4vw, 22px); }
}

/* Wide and upright (tablets): the four rows sit side by side. */
@media (orientation: portrait) and (min-width: 700px) {
  .tray-rows { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 900px; }
}

/* On its side: the tray moves to the side so the table keeps its height. */
@media (orientation: landscape) {
  .app {
    grid-template: 'bar bar' auto 'tray table' 1fr / clamp(170px, 22vw, 260px) minmax(0, 1fr);
  }
  .tray {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    border-top: 0;
    border-inline-end: 2px solid var(--noor-surface-variant);
    overflow-y: auto;
    touch-action: pan-y;
  }
  .tray-rows { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .tray-bin { flex-direction: column; }
}

/* On its side and short (phones): two columns, so nothing needs scrolling. */
@media (orientation: landscape) and (max-height: 480px) {
  .app { grid-template-columns: clamp(260px, 40vw, 330px) minmax(0, 1fr); }
  .tray-rows { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
  .bar { padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 6px; }
  .icon-btn, .pill-btn { height: 38px; min-width: 38px; --depth: 3px; }
  .brand-mark { width: 32px; height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .float,
  .is-loose .piece-inner,
  .ghost,
  .cheer-stars svg,
  .hint,
  .cheer-card {
    animation: none;
  }
  .icon-btn,
  .pill-btn,
  .star svg,
  .tray-check {
    transition: none;
  }
}
