* { box-sizing: border-box; }

  :root{
    --paper:#fafafa;
    --white:#fff;
    --ink:#111;
    --grey:#555;
    --muted:#777;
    --yellow:#FFF2A8;
    --green:#CFF5D2;
    --blue:#D9EFFF;
    --purple:#E7D8FF;
    --pink:#FFD6E7;
    --peach:#FFDDB8;
    --mint:#CDEFEA;
    --border:3px solid #000;
    --shadow:4px 4px 0 #000;
    --font:'Fira Code', monospace;
  }

  html, body {
    margin:0;
    padding:0;
    min-height:100%;
    background:
      radial-gradient(circle at 8% 12%,rgba(0,0,0,.025),transparent 18rem),
      radial-gradient(circle at 92% 55%,rgba(0,0,0,.025),transparent 22rem),
      var(--paper);
    color:var(--ink);
    font-family:var(--font);
    -webkit-font-smoothing:antialiased;
  }

  body{
    min-height:100dvh;
    display:flex;
    flex-direction:column;
    overflow-x:hidden;
    overflow-y:hidden;
  }

  button,input{
    font-family:var(--font);
  }

  /* =========================================================
     TOP BAR — same paper / highlighter visual language
     ========================================================= */
  .topbar{
    flex-shrink:0;
    padding:14px clamp(14px,3vw,34px) 12px;
    display:flex;
    justify-content:space-between;
    align-items:center;
    flex-wrap:wrap;
    gap:10px 18px;
    border-bottom:var(--border);
    background:rgba(250,250,250,.96);
    font-size:10px;
    letter-spacing:.08em;
    text-transform:uppercase;
  }

  .topbar > span{
    position:relative;
    display:inline-block;
    padding:3px 6px;
    font-size:15px;
    font-weight:800;
    z-index:0;
  }

  .topbar > span::before{
    content:"";
    position:absolute;
    left:-2px;
    right:-4px;
    bottom:1px;
    height:9px;
    background:var(--yellow);
    transform:rotate(-1deg);
    z-index:-1;
  }

  .topbar > div{
    display:flex;
    gap:10px;
    align-items:center;
  }

  #status{
    color:var(--grey);
    font-size:13px;
    font-weight:600;
  }

  /* =========================================================
     MAIN THREE-STAGE PLAYGROUND
     ========================================================= */
  .main{
    flex:1;
    min-height:0;
    width:min(1540px,94%);
    margin:0 auto;
    display:grid;
    grid-template-columns:minmax(0,1fr) 100px minmax(0,1.15fr);
    gap:20px;
    padding:22px 0 28px;
    overflow:visible;
  }

  .panel{
    position:relative;
    min-width:0;
    min-height:0;
    display:flex;
    flex-direction:column;
    overflow:hidden;
    background:var(--white);
    border:var(--border);
    border-radius:2px 5px 3px 2px;
    box-shadow:var(--shadow);
  }

  .panel::after{
    content:"";
    position:absolute;
    left:10px;
    right:14px;
    top:-5px;
    height:2px;
    background:#000;
    opacity:.7;
    transform:rotate(.15deg);
    pointer-events:none;
  }

  .panel-header{
    position:relative;
    flex-shrink:0;
    padding:12px 16px;
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:10px;
    border-bottom:var(--border);
    background:#fff;
  }

  .panel-title{
    position:relative;
    display:inline-block;
    padding:2px 5px;
    font-size:15px;
    font-weight:800;
    letter-spacing:-.02em;
    z-index:0;
  }

  .panel-title::before{
    content:"";
    position:absolute;
    left:-2px;
    right:-5px;
    bottom:0;
    height:7px;
    background:var(--blue);
    transform:rotate(-1deg);
    z-index:-1;
  }

  .panel-sub{
    color:var(--muted);
    font-size:12px;
    line-height:1.35;
  }

  /* =========================================================
     CODE EDITOR
     ========================================================= */
  .editor-wrap{
    flex:1;
    display:flex;
    min-height:0;
    overflow:hidden;
    position:relative;
    background:#fff;
  }

  .gutter{
    width:50px;
    flex-shrink:0;
    background:#f5f5f5;
    border-right:2px solid #000;
    text-align:right;
    padding:15px 8px 15px 0;
    color:#aaa;
    font-size:16px;
    line-height:27px;
    user-select:none;
    overflow:hidden;
    white-space:pre;
  }

  .editor-area{
    flex:1;
    min-width:0;
    position:relative;
    overflow:auto;
    background:#fff;
  }

  #code{
    min-height:100%;
    padding:15px 12px;
    margin:0;
    outline:none;
    border:none;
    font-size:16px;
    line-height:27px;
    font-family:var(--font);
    white-space:pre;
    word-wrap:normal;
    overflow-wrap:normal;
    font-variant-ligatures:none;
    font-feature-settings:"liga" 0,"calt" 0;
    font-kerning:none;
    -webkit-font-kerning:none;
    text-rendering:geometricPrecision;
    letter-spacing:0;
    word-spacing:0;
    tab-size:4;
    -moz-tab-size:4;
    caret-color:#000;
    color:#000;
    background:#fff;
  }

  #code:empty:before{
    content:attr(data-placeholder);
    color:#aaa;
    pointer-events:none;
  }

  #code span.kw{color:#8b3d00;font-weight:700}
  #code span.bi{color:#6f268f;font-weight:700}
  #code span.cm{color:#a40000}
  #code span.st{color:#16723a}
  #code span.df{color:#174ca4;font-weight:700}
  #code span.nu{color:#000}
  #code::selection,
  #code::-moz-selection{background:#d9efff}

  /* =========================================================
     CENTER RUN ACTION
     ========================================================= */
  .center-col{
    min-width:0;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:15px;
  }

  .f5-btn{
    width:84px;
    height:84px;
    flex-shrink:0;
    border:var(--border);
    border-radius:2px 50% 4px 50%;
    background:var(--yellow);
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    font-family:var(--font);
    cursor:pointer;
    user-select:none;
    box-shadow:4px 4px 0 #000;
    transform:rotate(-1deg);
    transition:transform .12s ease,box-shadow .12s ease,background-color .15s ease;
  }

  .f5-btn:hover{
    transform:translate(-1px,-1px) rotate(-1deg);
    box-shadow:5px 5px 0 #000;
  }

  .f5-btn:active{
    transform:translate(2px,2px) rotate(-1deg);
    box-shadow:1px 1px 0 #000;
  }

  .f5-btn.flash{
    background:var(--green)!important;
    transform:scale(1.06) rotate(-1deg);
  }


  /* =========================================================
     RIGHT OUTPUT / TURTLE
     ========================================================= */
  .right-stack{
    min-width:0;
    min-height:0;
    display:flex;
    flex-direction:column;
    gap:18px;
  }

  .left-panel{
    min-width:0;
    min-height:0;
  }

  .output-content{
    flex:1;
    min-height:0;
    overflow:auto;
    padding:15px;
    font-size:16px;
    line-height:27px;
    white-space:pre-wrap;
    word-break:break-word;
    user-select:text;
    display:block;
    background:#fff;
    color:#000;
  }

  .output-line{
    display:block;
    min-height:27px;
    white-space:pre-wrap;
    word-break:break-word;
  }

  /* Keep long program output inside the Output Window.
     The page itself remains scrollable so the footer is always reachable. */
  .output-content{
    overflow-y:auto;
    overflow-x:hidden;
    overscroll-behavior:contain;
    scrollbar-width:thin;
    scrollbar-color:#111 #f1f1f1;
  }

  .output-content::-webkit-scrollbar{
    width:10px;
  }

  .output-content::-webkit-scrollbar-track{
    background:#f1f1f1;
    border-left:2px solid #000;
  }

  .output-content::-webkit-scrollbar-thumb{
    background:#fff;
    border:2px solid #000;
    border-radius:0;
    box-shadow:2px 2px 0 #000;
  }

  .output-content::-webkit-scrollbar-thumb:hover{
    background:var(--yellow);
  }

  .turtle-wrap{
    flex:1;
    min-height:0;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:14px;
    background:
      linear-gradient(rgba(0,0,0,.025) 1px,transparent 1px),
      linear-gradient(90deg,rgba(0,0,0,.025) 1px,transparent 1px),
      #fff;
    background-size:25px 25px;
    overflow:auto;
  }

  canvas#turtle-canvas{
    width:100%;
    max-width:520px;
    height:auto;
    aspect-ratio:5/4;
    display:block;
    border:2px solid #000;
    border-radius:2px;
    background:#fff;
    box-shadow:3px 3px 0 #000;
  }

  .toggle-btn{
    border:var(--border);
    border-radius:2px 4px 2px 3px;
    padding:7px 12px;
    background:var(--white);
    font-family:var(--font);
    font-size:12px;
    font-weight:800;
    cursor:pointer;
    box-shadow:3px 3px 0 #000;
    transition:transform .12s ease,box-shadow .12s ease,background .12s ease;
  }

  .toggle-btn.on{
    background:var(--green);
    color:#000;
  }

  .toggle-btn:hover{
    transform:translate(-1px,-1px);
    box-shadow:4px 4px 0 #000;
  }

  #clearCanvas{
    color:#000!important;
    font-family:var(--font)!important;
    font-weight:700;
    text-decoration:underline!important;
  }

  /* =========================================================
     INPUT MODAL
     ========================================================= */
  #inputModalOverlay{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,.22);
    display:none;
    align-items:center;
    justify-content:center;
    z-index:9999;
    backdrop-filter:blur(2px);
    padding:16px;
  }

  #inputModalOverlay.show{display:flex}

  #inputModal{
    background:#fff;
    border:var(--border);
    border-radius:2px 5px 3px 2px;
    padding:0;
    min-width:0;
    max-width:520px;
    width:min(480px,100%);
    box-shadow:7px 7px 0 #000;
    overflow:hidden;
    animation:popupIn .18s ease-out;
  }

  @keyframes popupIn{
    from{transform:translateY(8px) scale(.97);opacity:0}
    to{transform:translateY(0) scale(1);opacity:1}
  }

  #inputModal .modal-header{
    padding:13px 17px;
    border-bottom:var(--border);
    display:flex;
    justify-content:space-between;
    align-items:center;
    background:var(--yellow);
  }

  #inputModal .modal-title{
    font-size:12px;
    font-weight:800;
    letter-spacing:.04em;
    text-transform:uppercase;
  }

  #inputModal .modal-body{
    padding:18px 17px 14px;
  }

  #inputModalPrompt{
    font-size:13px;
    font-weight:600;
    margin-bottom:12px;
    color:#000;
    white-space:pre-wrap;
    word-break:break-word;
  }

  #inputModalField{
    width:100%;
    border:var(--border);
    border-radius:2px;
    padding:9px 11px;
    font-family:var(--font);
    font-size:14px;
    outline:none;
    background:#fff;
  }

  #inputModalField:focus{
    background:var(--blue);
    box-shadow:3px 3px 0 #000;
  }

  #inputModal .modal-footer{
    padding:10px 17px 15px;
    display:flex;
    gap:10px;
    justify-content:flex-end;
  }

  .modal-btn{
    border:var(--border);
    border-radius:2px 4px 2px 3px;
    padding:8px 17px;
    font-family:var(--font);
    font-size:10px;
    font-weight:800;
    cursor:pointer;
    box-shadow:3px 3px 0 #000;
    transition:transform .12s ease,box-shadow .12s ease;
  }

  .modal-btn.cancel{
    background:#fff;
    color:#000;
  }

  .modal-btn.ok{
    background:var(--green);
    color:#000;
  }

  .modal-btn:hover{
    transform:translate(-1px,-1px);
    box-shadow:4px 4px 0 #000;
  }

  .modal-btn:active{
    transform:translate(2px,2px);
    box-shadow:1px 1px 0 #000;
  }

  /* =========================================================
     RESPONSIVE
     ========================================================= */
  @media(max-width:1050px){
    html,body{
      overflow:auto;
      height:auto;
    }

    body{
      min-height:100dvh;
    }

    .main{
      grid-template-columns:1fr;
      overflow:visible;
      min-height:auto;
      padding:18px 0 26px;
    }

    .left-panel{
      height:52vh;
      min-height:340px;
    }

    .center-col{
      width:100%;
      flex-direction:row;
      padding:4px 0;
    }

    .right-stack{
      min-height:520px;
    }

    .right-stack .panel{
      min-height:240px;
    }
  }

  @media(max-width:650px){
    .topbar{
      align-items:flex-start;
      padding:11px 14px;
    }


    .site-footer{
      padding:0 4% 20px;
      font-size:15px;
    }


    .topbar > span{
      width:100%;
      font-size:15px;
    }

    .topbar > div{
      width:100%;
      justify-content:space-between;
    }

    .main{
      width:94%;
      gap:14px;
      padding-top:14px;
    }

    .panel{
      box-shadow:3px 3px 0 #000;
    }

    .panel-header{
      padding:10px 12px;
    }

    .panel-title{
      font-size:15px;
    }

    .panel-sub{
      font-size:12px;
    }

    .left-panel{
      height:54vh;
      min-height:310px;
    }

    .gutter{
      width:40px;
      padding-right:6px;
      font-size:16px;
      line-height:27px;
    }

    #code{
      padding:12px 9px;
      font-size:16px;
      line-height:27px;
    }

    .center-col{
      gap:12px;
    }

    .f5-btn{
      width:70px;
      height:70px;
    }

    .right-stack{
      min-height:500px;
      gap:14px;
    }

    .output-content{
      font-size:13px;
      line-height:23px;
      padding:12px;
    }

    .output-line{
      min-height:23px;
    }

    .turtle-wrap{
      min-height:260px;
      padding:10px;
    }

    .toggle-btn{
      padding:6px 9px;
    }

    #inputModal .modal-body{
      padding:15px 13px 12px;
    }

    #inputModal .modal-footer{
      padding:9px 13px 13px;
    }
  }

  @media(max-width:420px){
    .main{
      width:95%;
    }

    .panel-header{
      align-items:flex-start;
    }

    .panel-sub{
      max-width:42%;
      text-align:right;
    }

    .left-panel{
      height:52vh;
      min-height:290px;
    }

    #code{
      font-size:16px;
      line-height:27px;
    }

    .gutter{
      font-size:16px;
      line-height:27px;
    }

    .f5-btn{
      width:64px;
      height:64px;
    }

    .right-stack{
      min-height:460px;
    }

    .turtle-wrap{
      min-height:220px;
    }
  }


  /* =========================================================
     FOOTER — reference-image layout
     ========================================================= */
  footer.site-footer.igcs-footer{
    flex-shrink:0;
    width:100%;
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:var(--igcs-space-4);
    padding:calc(var(--igcs-space-5) - 11px) clamp(16px,3vw,34px);
    min-height:0;
    border-top:var(--igcs-border);
    background:var(--igcs-white);
    color:var(--igcs-grey);
    font-size:14px;
    line-height:1.3;
    letter-spacing:-.02em;
  }

  .site-footer-left,
  .site-footer-right{
    display:flex;
    align-items:center;
    white-space:nowrap;
  }

  .site-footer-left{
    gap:4px;
  }

  .site-footer-name{
    position:relative;
    display:inline-block;
    font-weight:700;
    z-index:0;
  }

  .site-footer-name::before{
    content:"";
    position:absolute;
    left:-5px;
    right:-5px;
    bottom:1px;
    height:10px;
    background:var(--yellow);
    border-radius:3px;
    transform:rotate(-1deg);
    z-index:-1;
  }

  .site-footer-right{
    font-weight:500;
    color:#333;
  }

  @media print{
    html,body{
      overflow:visible;
    }

    .topbar{
      position:static;
    }

    .site-footer{
      padding:18px 4% 12px;
    }

    .main{
      width:100%;
      display:block;
      overflow:visible;
      padding:10px;
    }

    .panel,
    .f5-btn{
      box-shadow:none;
      break-inside:avoid;
    }

    .center-col{
      margin:15px 0;
    }
  }


  /* FINAL LAYOUT FIX: keep the page fixed and scroll only long output */
  html, body {
    height:100%;
    min-height:0;
    overflow:hidden;
  }

  body {
    min-height:100dvh;
  }

  .main {
    box-sizing:border-box;
    min-height:0;
    overflow:hidden;
  }

  .left-panel,
  .right-stack {
    height:100%;
    min-height:0;
  }

  .right-stack {
    overflow:hidden;
  }

  #outputPanel {
    min-height:0 !important;
    overflow:hidden;
  }

  #output {
    min-height:0 !important;
    height:auto;
    overflow-y:auto !important;
    overflow-x:hidden !important;
    flex:1 1 auto;
  }

  .site-footer {
    flex-shrink:0;
  }

  @media (max-width:1050px) {
    html, body {
      height:100%;
      min-height:0;
      overflow:hidden;
    }

    .main {
      min-height:0;
      height:auto;
      overflow:hidden;
    }

    .right-stack {
      height:auto;
      min-height:0;
      overflow:hidden;
    }
  }
