  :root{
    --bone:#F2ECDD;
    --panel:#FFFDF7;
    --ink:#2B2620;
    --line:#D8CFB8;
    --line-bold:#3A3630;
    --brick:#A8503A;
    --brick-dark:#8A3E2C;
    --gold:#C99A3E;
    --sage:#6B7A52;
    --shadow:0 1px 2px rgba(43,38,32,0.08);
  }
  *{box-sizing:border-box;}
  html{scroll-behavior:smooth;}
  body{
    margin:0; background:var(--bone); color:var(--ink);
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
    min-height:100vh;
  }
  h1,h2,h3{font-family:Georgia,'Times New Roman',serif; font-weight:normal; margin:0 0 4px;}
  .topbar{
    display:flex; align-items:baseline; gap:14px; padding:18px 24px 14px;
    border-bottom:2px solid var(--line-bold);
  }
  .topbar h1{font-size:22px; letter-spacing:0.02em;}
  .topbar .sub{font-size:12px; color:#8a7f68; letter-spacing:0.08em; text-transform:uppercase;}
  .screen{padding:20px 24px 60px;}
  .hidden{display:none !important;}

  /* setup */
  .ruler{
    height:14px; margin:0 0 26px;
    background-image:repeating-linear-gradient(90deg, var(--line-bold) 0 1px, transparent 1px 10px);
    background-size:100px 100%; opacity:0.5;
  }
  .setup-grid{display:grid; grid-template-columns:1fr 1fr; gap:22px; max-width:760px;}
  @media (max-width:640px){ .setup-grid{grid-template-columns:1fr;} }
  fieldset{
    border:1px solid var(--line); border-radius:10px; padding:16px 18px 18px;
    background:var(--panel); box-shadow:var(--shadow);
  }
  legend{font-family:Georgia,serif; font-size:15px; padding:0 6px;}
  label{display:block; font-size:12.5px; margin:10px 0 4px; color:#5a5140;}
  input[type=number], input[type=text], select{
    width:100%; padding:8px 9px; border:1px solid var(--line); border-radius:8px;
    font-size:14px; background:#fff; color:var(--ink); transition:border-color .15s, box-shadow .15s;
  }
  input[type=number]:focus, input[type=text]:focus, select:focus{
    outline:none; border-color:var(--brick); box-shadow:0 0 0 3px rgba(168,80,58,.14);
  }
  .row2{display:flex; gap:10px;}
  .row2 > div{flex:1;}
  .hint{font-size:11.5px; color:#8a7f68; margin-top:4px; line-height:1.4;}
  .side-toggle{display:flex; gap:8px; margin-top:8px;}
  .side-toggle button{flex:1;}
  button{
    font-family:inherit; cursor:pointer; border:1px solid var(--line-bold);
    background:var(--panel); color:var(--ink); padding:9px 14px; border-radius:8px;
    font-size:13px; transition:background .15s, transform .08s, box-shadow .15s;
  }
  button:hover{background:#efe6d1; box-shadow:0 2px 6px rgba(43,38,32,.10);}
  button:active{transform:scale(0.97);}
  button.primary{background:var(--brick); border-color:var(--brick-dark); color:#fff;}
  button.primary:hover{background:var(--brick-dark);}
  button.active{background:var(--ink); color:#fff; border-color:var(--ink);}
  .cta-row{margin-top:22px; display:flex; gap:12px; align-items:center;}
  #setupError{color:var(--brick-dark); font-size:13px; margin-top:8px;}

  /* editor */
  .editor-wrap{display:flex; gap:18px; align-items:flex-start; flex-wrap:wrap;}
  .toolbar{
    width:230px; flex-shrink:0; background:var(--panel); border:1px solid var(--line);
    padding:14px; border-radius:10px; box-shadow:var(--shadow);
  }
  .toolbar h3{font-size:13px; text-transform:uppercase; letter-spacing:.06em; margin-bottom:8px; color:#5a5140;}
  .swatches{display:grid; grid-template-columns:repeat(6,1fr); gap:5px; margin-bottom:8px;}
  .swatch{
    width:100%; aspect-ratio:1; border-radius:6px; border:2px solid transparent; cursor:pointer;
    transition:transform .1s, box-shadow .1s;
  }
  .swatch:hover{transform:scale(1.08); box-shadow:0 2px 5px rgba(43,38,32,.18); z-index:1;}
  .swatch.selected{border-color:var(--ink); box-shadow:0 0 0 1px #fff inset;}
  .swatch.eraser{
    background:repeating-linear-gradient(45deg,#fff,#fff 3px,#eee 3px,#eee 6px);
  }
  .addcolor{display:flex; gap:6px; margin:8px 0 14px;}
  .addcolor input[type=color]{width:34px; height:30px; border:1px solid var(--line); padding:0; border-radius:6px;}
  .addcolor input[type=text]{flex:1; padding:6px;}
  .toolbar hr{border:none; border-top:1px solid var(--line); margin:14px 0;}
  .field-row{display:flex; align-items:center; justify-content:space-between; margin:8px 0;}
  .field-row label{margin:0; font-size:12.5px;}
  .info-line{font-size:12px; line-height:1.7; color:#5a5140;}
  .info-line b{color:var(--ink);}
  .stats{max-height:150px; overflow-y:auto; font-size:11.5px; margin-top:6px;}
  .stat-row{display:flex; align-items:center; gap:6px; padding:2px 0;}
  .stat-swatch{width:12px; height:12px; border-radius:2px; flex-shrink:0; border:1px solid rgba(0,0,0,.15);}
  .canvas-outer{
    flex:1; min-width:300px; background:var(--panel); border:1px solid var(--line);
    border-radius:10px; overflow:auto; max-height:calc(100vh - 32px); padding:10px; box-shadow:var(--shadow);
    position:sticky; top:16px;
  }
  .floating-zoom{
    position:sticky; float:right; bottom:14px; margin-top:10px; margin-right:10px;
    display:flex; align-items:center; gap:8px; background:rgba(255,253,247,.94);
    border:1px solid var(--line); border-radius:999px; padding:6px 12px; box-shadow:0 4px 14px rgba(43,38,32,.18);
    width:180px;
  }
  .floating-zoom input[type=range]{flex:1;}
  .floating-zoom button{padding:4px 10px; border-radius:999px;}
  #gridCanvas{display:block; background:#fff; cursor:crosshair; image-rendering:pixelated; touch-action:none;}
  .save-note{font-size:11px; color:#8a7f68; margin-top:10px; min-height:14px;}
  .zoomrow{display:flex; align-items:center; gap:8px;}
  .zoomrow input[type=range]{flex:1;}
  @keyframes modalIn{ from{opacity:0; transform:scale(.96) translateY(6px);} to{opacity:1; transform:scale(1) translateY(0);} }
  .modal-box{animation:modalIn .18s ease-out;}

/* ===================== language switcher ===================== */
.lang-switch{ margin-left:auto; display:flex; gap:4px; align-self:center; }
.lang-btn{
  padding:5px 9px; font-size:11px; letter-spacing:.04em; border-radius:6px;
  border:1px solid var(--line); background:var(--panel); color:#5a5140;
}
.lang-btn.active{ background:var(--ink); color:#fff; border-color:var(--ink); }

/* ===================== feedback ===================== */
.feedback-btn{
  margin-left:8px; white-space:nowrap; align-self:center;
  background:var(--sage); border-color:#54603f; color:#fff;
}
.feedback-btn:hover{ background:#5a6745; }
#feedbackFormBox label{ display:block; font-size:12.5px; margin:10px 0 5px; color:#5a5140; }
.feedback-stars{ display:flex; gap:6px; margin-bottom:4px; }
.feedback-star{
  font-size:26px; line-height:1; padding:2px 6px; border:none; background:none;
  color:var(--gold); box-shadow:none;
}
.feedback-star:hover{ background:none; box-shadow:none; transform:scale(1.1); }
.feedback-textarea{
  width:100%; padding:8px 9px; border:1px solid var(--line); border-radius:8px;
  font-family:inherit; font-size:14px; resize:vertical; background:#fff; color:var(--ink);
}
.feedback-textarea:focus{ outline:none; border-color:var(--brick); box-shadow:0 0 0 3px rgba(168,80,58,.14); }

/* ===================== footer ===================== */
.site-footer{
  border-top:1px solid var(--line); margin-top:32px; padding:22px 24px 28px;
  background:var(--panel);
}
.site-footer-inner{ max-width:960px; margin:0 auto; text-align:center; }
.site-footer-brand{ font-family:Georgia,serif; font-size:15px; letter-spacing:.06em; margin-bottom:4px; }
.site-footer-copy{ font-size:11.5px; color:#8a7f68; margin-bottom:10px; }
.site-footer-links{ display:flex; flex-wrap:wrap; justify-content:center; gap:14px; }
.site-footer-links a{
  font-size:12px; color:#5a5140; text-decoration:none; border-bottom:1px solid transparent;
}
.site-footer-links a:hover{ border-bottom-color:#5a5140; }

/* ===================== legal pages ===================== */
.legal-page{ max-width:760px; margin:0 auto; padding:32px 24px 20px; line-height:1.65; font-size:14.5px; }
.legal-page h1{ font-size:24px; margin-bottom:6px; }
.legal-page h2{ font-size:17px; margin-top:28px; }
.legal-page .legal-updated{ font-size:12px; color:#8a7f68; margin-bottom:24px; }
.legal-page .placeholder{ background:#fff3cd; border:1px solid #e9d38a; border-radius:6px; padding:1px 6px; font-family:monospace; font-size:.92em; }
.legal-page ul{ padding-left:20px; }
.legal-page a{ color:var(--brick); }
.back-link{ display:inline-block; margin:20px 24px 0; font-size:13px; color:#5a5140; text-decoration:none; }
.back-link:hover{ text-decoration:underline; }

/* ===================== responsive / mobile & tablet ===================== */
@media (max-width: 680px){
  .topbar{ flex-wrap:wrap; padding:14px 16px 12px; gap:10px; }
  .topbar .sub{ order:3; width:100%; }
  .screen{ padding:14px 14px 40px; }

  /* Stack the editor: schema first (most important), controls below, natural page scroll */
  .editor-wrap{ flex-direction:column; }
  .toolbar{ width:100%; order:2; position:static; }
  .canvas-outer{
    width:100%; order:1; position:static; max-height:62vh; box-shadow:var(--shadow);
  }
  .floating-zoom{ float:none; position:sticky; margin:8px auto 0; }

  /* Bigger touch targets */
  button{ padding:11px 14px; font-size:14px; }
  input[type=number], input[type=text], select{ padding:10px 10px; font-size:16px; } /* 16px prevents iOS auto-zoom on focus */
  .swatches{ grid-template-columns:repeat(8,1fr); }

  .setup-grid{ grid-template-columns:1fr; }
  .modal-box{ max-width:96vw !important; width:96vw !important; }
}

@media (max-width: 480px){
  .topbar h1{ font-size:19px; }
  .toolbar h3{ font-size:12.5px; }
  .swatches{ grid-template-columns:repeat(6,1fr); }
  .site-footer-links{ gap:10px 16px; }
  .lang-switch{ order:2; margin-left:0; }
  .feedback-btn{ order:4; margin-left:0; }
}

/* Never allow the page itself to scroll sideways.
   `overflow-x: clip` (not `hidden`) is used deliberately: per the CSS spec,
   whenever overflow-x and overflow-y differ and either one is "hidden"
   (or auto/scroll), the browser silently forces the other axis to "auto" as
   well — turning html/body into their own scroll containers and breaking
   `position: sticky` on .canvas-outer (the schema stopped staying fixed
   while scrolling). "clip" is exempt from that rule, so it blocks sideways
   overflow without hijacking vertical scrolling. */
html, body{ overflow-x:clip; overflow-y:visible; max-width:100%; }
