:root {
  --ink: #26353a;
  --muted: #6d7d7d;
  --line: #d9e3df;
  --paper: #fbfaf5;
  --teal: #287a72;
  --teal-dark: #1d5d58;
  --coral: #df806d;
  --gold: #f6cf70;
  --shadow: 0 20px 60px rgba(33, 63, 60, .09);
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(rgba(40, 122, 114, .09) .8px, transparent .8px), linear-gradient(135deg, #fbfaf5 0%, #f4f7f0 100%);
  background-size: 18px 18px, 100% 100%;
  font-family: "Noto Sans Arabic", Tahoma, sans-serif;
}

.coding-page { width: min(760px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0; }
.back-link { display: inline-block; margin-bottom: 15px; color: var(--teal-dark); font-size: 14px; font-weight: 700; text-decoration: none; }
.coding-panel { padding: clamp(20px, 4vw, 38px); border: 1px solid rgba(205, 220, 214, .9); border-radius: 18px; background: rgba(255, 255, 252, .88); box-shadow: var(--shadow); }
.coding-header { text-align: center; }
.coding-header > p:first-child { margin: 0; color: var(--coral); font-size: 13px; font-weight: 700; }
h1, h2 { margin: 0; color: var(--teal-dark); }
h1 { font-size: clamp(32px, 5vw, 48px); }
.instructions { max-width: 530px; margin: 6px auto 0; color: var(--muted); font-size: 15px; line-height: 1.8; }
.letter-legend { display: flex; justify-content: center; gap: 14px; margin: 22px 0 16px; }
.letter-legend div { display: flex; align-items: center; gap: 8px; min-width: 135px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fffdf7; }
.letter-legend span { color: var(--muted); font-size: 12px; }
.letter-legend strong { margin-inline-start: auto; color: var(--teal-dark); font-size: 28px; line-height: 1; }
.coding-board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; width: min(100%, 460px); margin: 0 auto; direction: ltr; }
.coding-cell { position: relative; display: grid; aspect-ratio: 1; place-items: center; border: 1px solid #c9d9c6; border-radius: 12px; background: #f7f6e8; transition: transform 180ms ease, background 180ms ease; }
.coding-cell.start { background: #e1f0e9; }
.coding-cell.target { background: #fff1d1; }
.coding-cell.player { transform: scale(.92); background: var(--teal); box-shadow: 0 5px 14px rgba(40, 122, 114, .32); }
.coding-cell.player::after { content: "●"; color: white; font-size: clamp(20px, 4vw, 34px); }
.coding-cell.letter-cell { color: var(--teal-dark); font-size: clamp(26px, 5vw, 44px); font-weight: 700; }
.coding-cell.target.letter-cell { color: #8a5c19; }
.program-panel { max-width: 550px; margin: 24px auto 0; padding-top: 19px; border-top: 1px solid var(--line); text-align: center; }
.program-panel h2 { font-size: 23px; }
.command-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 34px; margin: 11px 0 0; padding: 0; list-style: none; direction: ltr; }
.command-list li { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 7px; color: white; background: var(--teal); font-size: 20px; }
.program-placeholder { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.program-placeholder[hidden] { display: none; }
.arrow-controls { display: grid; grid-template-columns: repeat(3, 42px); justify-content: center; gap: 6px; margin-top: 14px; direction: ltr; }
.arrow-controls button { grid-column: 2; width: 42px; height: 42px; border: 0; border-radius: 9px; color: var(--teal-dark); background: #e5f0e7; cursor: pointer; font-size: 24px; }
.arrow-controls button[data-direction="left"] { grid-column: 1; grid-row: 2; }
.arrow-controls button[data-direction="down"] { grid-column: 2; grid-row: 2; }
.arrow-controls button[data-direction="right"] { grid-column: 3; grid-row: 2; }
.arrow-controls button:hover, .arrow-controls button:focus-visible { color: white; background: var(--teal); outline: none; }
.game-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.action-button { padding: 8px 12px; border: 0; border-radius: 7px; color: white; background: var(--teal); cursor: pointer; font: inherit; font-size: 13px; }
.action-button.secondary { color: var(--teal-dark); background: rgba(40, 122, 114, .12); }
.action-button:disabled { cursor: wait; opacity: .6; }
.game-status { min-height: 1.5em; margin: 11px 0 0; color: var(--muted); font-size: 13px; }

@media (max-width: 460px) {
  .coding-page { width: min(100% - 22px, 760px); padding-top: 16px; }
  .coding-panel { padding: 20px 13px; }
  .letter-legend { gap: 7px; }
  .letter-legend div { min-width: 0; flex: 1; }
}
