/* Turtle Coding (tools/turtle-coding/). The Coding Sandbox has its own stylesheet, css/coding-sandbox.css. */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background: #f1f5f9; min-height: 100vh; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }

/* ===== Site Header ===== */
.site-header { background: white; border-bottom: 1px solid #e5e7eb; height: 64px; position: sticky; top: 0; z-index: 100; }
.header-inner { max-width: 100%; height: 100%; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }
.site-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.site-logo-img { height: 44px; width: auto; display: block; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a { font-size: 14px; font-weight: 600; color: #64748b; text-decoration: none; padding: 8px 14px; border-radius: 8px; transition: all 0.2s; }
.nav-links a:hover { background: #f1f5f9; color: #1a1a2e; }
.nav-links a.active { background: #fef3c7; color: #92400e; }
.hamburger-btn { display: none; background: none; border: none; cursor: pointer; padding: 8px; z-index: 200; }
.hamburger-btn span { display: block; width: 24px; height: 2.5px; background: #64748b; border-radius: 2px; transition: all 0.3s; margin: 5px 0; }
.hamburger-btn.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5.5px); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; }
.hamburger-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5.5px); }
@media (max-width: 768px) {
  .hamburger-btn { display: block; }
  .nav-links { display: none; position: absolute; top: 64px; left: 0; right: 0; background: white; flex-direction: column; padding: 8px 16px 16px; border-bottom: 1px solid #e5e7eb; box-shadow: 0 4px 12px rgba(0,0,0,0.08); gap: 2px; }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 12px 16px; font-size: 16px; border-radius: 8px; }
  .site-header { padding: 0 16px; }
}

/* ===== Layout ===== */
.main-container { display: grid; grid-template-columns: 300px 1fr; }
.main-container.sidebar-collapsed { grid-template-columns: 0 1fr; }
.sidebar { background: #f7fafc; padding: 24px 20px; box-shadow: 4px 0 20px rgba(0,0,0,0.1); overflow-y: auto; height: calc(100vh - 64px); position: sticky; top: 64px; transition: width 0.25s, padding 0.25s; }
.sidebar.collapsed { width: 0; padding: 0; overflow: hidden; min-width: 0; }
.sidebar h1 { font-family: 'DM Sans', -apple-system, sans-serif; font-size: 20px; font-weight: 700; color: #1a202c; margin-bottom: 4px; }
.sidebar .subtitle { font-size: 12px; color: #718096; margin-bottom: 20px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #f59e0b; text-decoration: none; margin-bottom: 16px; }
.control-group { margin-bottom: 16px; }
.control-group > label { display: block; font-size: 13px; font-weight: 600; color: #2d3748; margin-bottom: 6px; }
.control-group select { width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit; border: 2px solid #e2e8f0; border-radius: 8px; background: white; color: #2d3748; cursor: pointer; }
.actions { display: grid; gap: 8px; margin-bottom: 8px; }
.actions.pair { grid-template-columns: 1fr 1fr; }
.actions.trio { grid-template-columns: 44px 1fr 44px; }
.action-btn, .clear-btn { width: 100%; min-height: 42px; padding: 10px 12px; font-family: inherit; font-size: 13px; font-weight: 600; color: #64748b; background: white; border: 2px solid #e2e8f0; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.action-btn:hover, .clear-btn:hover { border-color: #f59e0b; color: #f59e0b; background: #fffbeb; }
body.pv-tool .sidebar [hidden] { display: none !important; }
body.pv-tool .sidebar .action-btn[hidden], body.pv-tool .sidebar .actions[hidden], body.pv-tool .sidebar .adv-checkbox-row[hidden] { display: none !important; }   /* purple-tool.css shows every sidebar button */
body.pv-tool .sidebar .actions.pair, body.pv-tool .sidebar .actions.trio { margin-top: 0 !important; }
body.pv-tool .sidebar .actions.trio { grid-template-columns: 48px 1fr 48px; }
body.pv-tool .sidebar .actions.trio button { padding: 11px 6px !important; font-size: 14px !important; }
body.pv-tool .sidebar .actions.pair button { padding: 11px 8px !important; font-size: 14px !important; }
body.pv-tool .sidebar .actions + .actions { margin-top: 0 !important; }
.puzzle-num { display: flex; align-items: center; justify-content: center; font: 600 15px 'Fredoka', 'DM Sans', sans-serif; color: #341e60; }
.checkbox-section { margin: 8px 0 16px; }
.adv-checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; color: #2d3748; cursor: pointer; }
.adv-checkbox-row input[type=checkbox] { cursor: pointer; width: 14px; height: 14px; }
.help-text { font-size: 12px; line-height: 1.55; color: #718096; margin-top: 18px; }
.help-text kbd { font: 700 11px 'DM Sans', sans-serif; padding: 1px 5px; border: 1px solid #d6d0e6; border-bottom-width: 2px; border-radius: 4px; background: #fff; color: #341e60; }

.collapse-btn { position: fixed; top: 50%; left: 300px; transform: translateY(-50%); z-index: 500; background: white; border: 1px solid #e2e8f0; border-radius: 0 8px 8px 0; padding: 10px 6px; cursor: pointer; font-size: 12px; color: #718096; box-shadow: 2px 0 8px rgba(0,0,0,0.08); transition: left 0.25s; line-height: 1; }
.collapse-btn.collapsed-pos { left: 0; }

/* ===== Workspace: the task line, then the world and the code ===== */
.workspace { display: flex; flex-direction: column; align-items: stretch; padding: 12px 18px 18px; overflow: hidden; height: calc(100vh - 64px); position: relative; min-width: 0; background: #fbf8f2; }
.fullscreen-btn, .sound-btn { position: absolute; top: 12px; right: 12px; background: white; border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px; cursor: pointer; color: #64748b; z-index: 10; display: flex; align-items: center; justify-content: center; }
.fullscreen-btn:hover, .sound-btn:hover { color: #634bf5; border-color: #634bf5; }
.fullscreen-btn svg, .sound-btn svg { width: 20px; height: 20px; }
.sound-btn { right: 58px; }
.sound-btn.alone { right: 12px; }
.sound-btn .snd-off, .sound-btn.off .snd-on { display: none; }
.sound-btn.off .snd-off { display: block; }

.readout { flex: none; min-height: 54px; margin: 0 100px 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; color: #341e60; }
.prompt { font: 600 21px/1.25 'Fredoka', 'DM Sans', sans-serif; }
.status { font: 600 16px/1.3 'DM Sans', -apple-system, sans-serif; color: #4a3f6b; min-height: 21px; }
.status.good { color: #15803d; }
.status.bad { color: #c2410c; }

.play { flex: 1 1 auto; min-height: 0; display: flex; gap: 16px; }
.play.stacked { flex-direction: column; gap: 12px; }
.stage-wrap { flex: 1 1 auto; min-width: 0; min-height: 0; position: relative; display: flex; flex-direction: column; }
.stage-box { flex: 1 1 auto; min-height: 0; position: relative; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; overflow: visible; }
#stage .hit { cursor: pointer; }
#stage.tool-on { cursor: crosshair; }

/* the bar over the world: edit tools (Free Build) or the puzzle number */
.stage-bar { flex: none; align-self: center; margin: 0 0 8px; z-index: 5; display: flex; gap: 6px; align-items: center; padding: 5px; background: rgba(255,255,255,.92); border: 2px solid #ece6f6; border-radius: 999px; box-shadow: 0 4px 14px rgba(52,30,96,.10); }
.tool { width: 46px; height: 46px; border-radius: 50%; border: 2px solid transparent; background: #f7f5fc; cursor: pointer; display: grid; place-items: center; padding: 0; }
.tool svg { width: 38px; height: 38px; overflow: visible; }
.tool:hover { border-color: #d9d0f5; }
.tool.on { border-color: #634bf5; background: #ece8ff; box-shadow: 0 0 0 3px rgba(99,75,245,.18); }
.tool .erase { font: 700 20px/1 'DM Sans', sans-serif; color: #8a7fa8; }
.pz-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: #f3f0fb; color: #341e60; font: 700 18px/1 'DM Sans', sans-serif; cursor: pointer; }
.pz-btn:hover { background: #e6e0fa; }
.pz-label { font: 600 17px 'Fredoka', 'DM Sans', sans-serif; color: #341e60; padding: 0 6px; white-space: nowrap; }

/* the you-did-it card over the world */
.win { position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 0) scale(.9); z-index: 6; min-width: 280px; max-width: calc(100% - 32px); padding: 16px 24px 16px; text-align: center; background: #fff; border-radius: 24px; box-shadow: 0 20px 50px rgba(52,30,96,.28); opacity: 0; pointer-events: none; transition: opacity .25s, transform .3s cubic-bezier(.2,1.4,.4,1); }
.win.show { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; }
.win h2 { font: 600 30px/1.1 'Fredoka', sans-serif; color: #341e60; margin-bottom: 6px; }
.win p { font: 600 16px/1.4 'DM Sans', sans-serif; color: #4a3f6b; margin-bottom: 16px; }
.win .stars { font-size: 30px; letter-spacing: 6px; margin-bottom: 6px; color: #f5b301; }
.win .row-b { display: flex; gap: 10px; justify-content: center; }
.win button { min-height: 44px; padding: 0 20px; border-radius: 999px; font: 700 15px 'DM Sans', sans-serif; cursor: pointer; border: 2px solid #e2dcf5; background: #fff; color: #341e60; }
.win button.go { background: #ff7800; border-color: #ff7800; color: #fff; }

/* ===== The code panel ===== */
.code { --fs: clamp(15px, 0.75vw + 7px, 21px); flex: 0 0 clamp(380px, 34%, 480px); min-height: 0; display: flex; flex-direction: column; background: #fff; border: 2px solid #ebe5f5; border-radius: 22px; box-shadow: 0 4px 20px rgba(52,30,96,.06); overflow: hidden; position: relative; }
.play.stacked .code { flex: 0 0 46%; min-height: 250px; }
.code-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.code-title { font: 600 19px 'Fredoka', 'DM Sans', sans-serif; color: #341e60; }
.code-count { font: 600 13px 'DM Sans', sans-serif; color: #8a7fa8; margin-right: auto; white-space: nowrap; }
.view-toggle { display: flex; padding: 3px; background: #f3f0fb; border-radius: 999px; }
.view-toggle button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; font: 700 12.5px 'DM Sans', sans-serif; color: #341e60; cursor: pointer; }
.view-toggle button.on { background: #341e60; color: #fff; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: #f3f0fb; color: #341e60; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: #e6e0fa; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; }

.palette { flex: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 14px 12px; border-bottom: 2px dashed #ece6f6; }
.pal { flex: 1 1 calc(50% - 8px); min-width: 0; display: flex; align-items: center; justify-content: center; gap: 7px; min-height: calc(var(--fs) * 2.55); padding: 6px 10px; border-radius: 14px; border: 2px solid; font: 600 calc(var(--fs) * var(--pk, 1))/1 'Fredoka', 'DM Sans', sans-serif; cursor: grab; touch-action: none; transition: transform .12s, box-shadow .12s; white-space: nowrap; }
.pal.wide4 { flex-basis: calc(25% - 8px); }
.pal.two { white-space: normal; line-height: 1.05; text-align: center; }
.pal:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(52,30,96,.12); }
.pal:active { transform: translateY(1px); }
.pal .ic, .card .ic { width: 1.2em; height: 1.2em; flex: none; }
.code.py .pal, .code.py .card { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-weight: 600; font-size: calc(var(--fs) * .86); }
.code.py .pal { font-size: calc(var(--fs) * .86 * var(--pk, 1)); }
.code.py .pal .ic, .code.py .card .ic { display: none; }
.code.running .palette { opacity: .45; pointer-events: none; }

.k-move { background: #eaf1ff; border-color: #b4cbfb; color: #1e3a8a; }
.k-move .ic { color: #2563eb; }
.k-turn { background: #fff2e8; border-color: #fdc9a3; color: #9a3412; }
.k-turn .ic { color: #f97316; }
.k-rep { background: #f1edff; border-color: #cbbffd; color: #4b35d6; }
.k-rep .ic { color: #634bf5; }
.k-pen { background: #eafaf0; border-color: #a9e9c0; color: #166534; }
.k-pen .ic { color: #16a34a; }

.program { flex: 1 1 auto; min-height: 0; overflow-y: auto; position: relative; padding: 10px 10px 48px 0; --ind: calc(var(--fs) * 1.7); --gut: calc(var(--fs) * 2.1); }
.program::-webkit-scrollbar { width: 8px; }
.program::-webkit-scrollbar-thumb { background: #e2dcf5; border-radius: 8px; }
.prow { position: relative; display: flex; align-items: center; min-height: calc(var(--fs) * 2.35 + 6px); padding: 3px 0 3px calc(var(--gut) + var(--d) * var(--ind)); }
.prow .ln { position: absolute; left: 0; width: calc(var(--gut) - 10px); text-align: right; font: 600 calc(var(--fs) * .68) 'DM Sans', sans-serif; color: #b9b0cf; font-variant-numeric: tabular-nums; }
.prow .bar { position: absolute; top: 0; bottom: 0; width: 7px; background: #cbbffd; }
.prow.end { min-height: 14px; padding-top: 0; padding-bottom: 0; }
.prow.end .foot { position: absolute; top: 0; height: 12px; width: calc(var(--fs) * 3.2); background: #cbbffd; border-radius: 0 7px 7px 7px; }
.prow.empty .hole { font: 600 calc(var(--fs) * .8) 'Fredoka', 'DM Sans', sans-serif; color: #a99fc6; border: 2px dashed #d9d0f5; border-radius: 12px; padding: 7px 12px; }
.code.py .prow.empty .hole { font-family: ui-monospace, Consolas, monospace; font-style: italic; border-style: dotted; }
.prow.empty.here .hole { border-color: #634bf5; color: #634bf5; background: #f6f3ff; }
.prow.empty.here.drop .hole { border-color: #ff7800; color: #c2410c; background: #fff4ea; }
.code.running .prow.empty.here .hole { border-color: #d9d0f5; color: #a99fc6; background: none; }
.card { display: inline-flex; align-items: center; gap: 7px; min-height: calc(var(--fs) * 2.25); padding: 4px 12px; border-radius: 13px; border: 2px solid; font: 600 var(--fs)/1 'Fredoka', 'DM Sans', sans-serif; cursor: grab; touch-action: none; transition: box-shadow .15s, transform .15s; white-space: nowrap; }
.card .num { display: inline-grid; place-items: center; min-width: 1.75em; height: 1.55em; padding: 0 .3em; border-radius: 9px; background: #fff; border: 2px solid currentColor; font: 700 calc(var(--fs) * .95)/1 'Google Sans Flex', 'Fredoka', sans-serif; cursor: pointer; }
.card .num:hover { background: #fffbe6; }
.card .swatch { width: 1.2em; height: 1.2em; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px currentColor; cursor: pointer; }
.code.py .card .num { font-family: inherit; border-width: 0; background: rgba(255,255,255,.75); min-width: 1.2em; }
.prow .del { margin-left: 6px; width: 32px; height: 32px; flex: none; border: 0; border-radius: 50%; background: none; color: #c4bcd8; font: 400 22px/1 'DM Sans', sans-serif; cursor: pointer; opacity: 0; }
.prow:hover .del, .prow.sel .del { opacity: 1; }
.prow .del:hover { color: #c0392b; background: #fdecea; }
.prow .round { margin-left: 8px; font: 700 calc(var(--fs) * .7) 'DM Sans', sans-serif; color: #634bf5; background: #f1edff; border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.prow.sel .card { box-shadow: 0 0 0 3px rgba(99,75,245,.35); }
.prow.run .card { box-shadow: 0 0 0 4px #ffcf4d, 0 0 18px rgba(255,170,0,.55); transform: scale(1.04); }
.prow.err .card { box-shadow: 0 0 0 4px #fca5a5, 0 0 14px rgba(239,68,68,.35); }
.program-empty { padding: 18px calc(var(--gut)) 0; font: 600 calc(var(--fs) * .85)/1.4 'Fredoka', 'DM Sans', sans-serif; color: #a99fc6; }
.caret { position: absolute; height: 4px; border-radius: 4px; background: #634bf5; pointer-events: none; box-shadow: 0 0 0 3px rgba(99,75,245,.15); transition: top .12s, left .12s; z-index: 2; }
.caret::before { content: ''; position: absolute; left: -9px; top: -5px; border: 7px solid transparent; border-left: 9px solid #634bf5; }
.caret.drop { background: #ff7800; box-shadow: 0 0 0 3px rgba(255,120,0,.2); }
.caret.drop::before { border-left-color: #ff7800; }
.code.running .caret { display: none; }

.transport { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px 12px; border-top: 2px solid #f3f0fb; background: #fdfcff; }
.tbtn { min-height: 46px; padding: 0 14px; border-radius: 999px; border: 2px solid #e2dcf5; background: #fff; color: #341e60; font: 700 15px 'DM Sans', sans-serif; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.tbtn:hover { border-color: #c9bcfd; }
.tbtn svg { width: 18px; height: 18px; }
.tbtn.go { background: #ff7800; border-color: #ff7800; color: #fff; padding: 0 18px; }
#resetBtn, .tbtn.speed { width: 46px; padding: 0; justify-content: center; }
.tbtn.go:hover { background: #ea6a00; border-color: #ea6a00; }
.tbtn.speed { margin-left: auto; }
.tbtn.speed svg { width: 24px; height: 24px; }
.speed .sp { display: none; }
.speed[data-speed="slow"] .sp[data-speed="slow"], .speed[data-speed="medium"] .sp[data-speed="medium"], .speed[data-speed="fast"] .sp[data-speed="fast"] { display: inline-flex; }

.picker { position: fixed; z-index: 3000; background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 14px 40px rgba(52,30,96,.25); display: grid; gap: 6px; }
.picker button { min-width: 44px; height: 44px; border-radius: 12px; border: 2px solid #ece6f6; background: #fff; font: 700 17px 'Google Sans Flex', 'Fredoka', sans-serif; color: #341e60; cursor: pointer; padding: 0 6px; }
.picker button:hover { border-color: #634bf5; }
.picker button.on { background: #634bf5; border-color: #634bf5; color: #fff; }
.picker .sw { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #ece6f6; }
.picker .sw.on { box-shadow: 0 0 0 3px #341e60; }
.drag-ghost { position: fixed; z-index: 4000; pointer-events: none; transform: translate(-50%, -50%) rotate(-3deg) scale(1.05); box-shadow: 0 12px 28px rgba(52,30,96,.3); opacity: .95; }
.drag-ghost.gone { opacity: .45; filter: grayscale(.6); }

.note { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: calc(100% - 24px); padding: 9px 16px; border-radius: 10px; background: #2d3748; color: white; font: 600 14px 'DM Sans', -apple-system, sans-serif; text-align: center; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 8; }
.note.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .caret, .card, .pal, .win { transition: none !important; }
}

/* ===== Fullscreen ===== */
body.is-fullscreen .site-header { display: none; }
body.is-fullscreen .main-container { grid-template-columns: 0 1fr; }
body.is-fullscreen .sidebar { position: fixed; top: 0; left: 0; height: 100vh; z-index: 600; width: 0; padding: 0; overflow: hidden; min-width: 0; }
body.is-fullscreen .sidebar.fs-expanded { width: 300px; padding: 24px 20px; overflow-y: auto; }
body.is-fullscreen .collapse-btn { top: 50%; left: 0; position: fixed; z-index: 601; }
body.is-fullscreen .collapse-btn.fs-expanded-pos { left: 300px; }
body.is-fullscreen .workspace { height: 100vh; padding: 14px 22px 18px; }
@media (min-width: 769px) { body.is-fullscreen .workspace { grid-column: 2; } }
body.is-fullscreen .code { --fs: clamp(16px, 0.8vw + 8px, 24px); }
body.is-fullscreen .prompt { font-size: 26px; }
body.is-fullscreen .status { font-size: 19px; }

/* ===== Phones: the world, then the code, then the options ===== */
@media (max-width: 768px) {
  .main-container { grid-template-columns: 1fr !important; display: flex; flex-direction: column; }
  .workspace { order: -1; height: auto; padding: 10px 8px 12px; }
  .sidebar { position: static !important; width: 100% !important; height: auto !important; max-height: none !important; border-top: 1px solid #e5e7eb; padding: 16px !important; }
  .collapse-btn { display: none !important; }
  .readout { min-height: 46px; margin: 0 90px 8px 4px; }
  .no-fs .readout { margin-right: 44px; }
  .prompt { font-size: 17px; }
  .status { font-size: 14px; }
  .play, .play.stacked { flex-direction: column; flex: none; }
  .stage-wrap { flex: none; height: min(96vw, 62vh); }
  .play.stacked .code, .code { flex: none; height: 430px; min-height: 0; }
  .tool { width: 40px; height: 40px; }
  .tool svg { width: 32px; height: 32px; }
}
@media (max-width: 760px) {
  body.pv-tool #mainContainer { display: flex !important; flex-direction: column; }
  body.pv-tool #workspace { order: -1; height: auto !important; max-height: none !important; overflow: visible !important; }
  body.pv-tool #sidebar { border-bottom: 0 !important; border-top: 1px solid var(--pv-line, #e5e7eb) !important; }
}
