:root{
    --bg:#fff7c7;          /* pastel yellow */
    --ink:#111827;
    --muted:#4b5563;
    --card:#ffffffcc;
    --grid:#111827;
    --accent:#2563eb;
    --shadow: 0 10px 25px rgba(0,0,0,.10);
    --radius: 18px;
  }
  *{box-sizing:border-box}
  body{
    margin:0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    background: var(--bg);
    color:var(--ink);
    touch-action: manipulation;
  }
  .wrap{
    max-width: 1100px;
    margin: 0 auto;
    padding: 18px 14px 28px;
  }
  .panel{
    background: var(--card);
    border: 2px solid rgba(17,24,39,.25);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
  }
  .row{
    display:flex;
    gap:12px;
    flex-wrap:wrap;
    align-items:center;
    justify-content:space-between;
  }
  .controls{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
    align-items:center;
  }
  label{
    font-weight:800;
    font-size: 16px;
  }
  select{
    font-size: 18px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 2px solid rgba(17,24,39,.35);
    background: #fff;
    min-height: 48px;
  }
  button{
    font-size: 18px;
    font-weight: 900;
    padding: 12px 16px;
    border-radius: 16px;
    border: 0;
    background: var(--accent);
    color:#fff;
    min-height: 52px;
    box-shadow: 0 8px 18px rgba(37,99,235,.25);
  }
  button:active{transform: translateY(1px)}
  button.secondary{
    background:#111827;
    box-shadow: 0 8px 18px rgba(17,24,39,.18);
  }
  .sentence{
    font-size: 22px;
    font-weight: 900;
    text-align:right;
    min-height: 30px;
  }
  .gridWrap{
    margin-top: 14px;
    position: relative;
  }

  /* Place value grid */
  table.pv{
    width:100%;
    border-collapse: collapse;
    table-layout: fixed;
    background:#fff;
    border: 3px solid var(--grid);
    border-radius: 14px;
    overflow:hidden;
  }
  .pv th, .pv td{
    border-right: 2px solid rgba(17,24,39,.75);
    text-align:center;
  }
  .pv th:last-child, .pv td:last-child{border-right:none}
  .pv thead th{
    height: 68px;
    font-size: clamp(16px, 2.0vw, 30px);
    font-weight: 1000;
    padding: 6px 2px;
    border-bottom: 2px solid rgba(17,24,39,.75);
    white-space: nowrap;
    overflow:hidden;
    text-overflow: clip;
  }
  .pv tbody td{
    height: 360px;
    vertical-align: top;
    padding-top: 18px;
    position: relative;
  }

  /* Decimal point markers (not their own column) */
  .onesHead, .onesCell{ position: relative; }
  .onesHead::after{
    content:"●";
    position:absolute;
    right:0;
    top: 50%;
    transform: translate(50%,-50%);
    font-size: 34px;
    line-height: 1;
    color:#000;
    pointer-events:none;
  }
  .onesCell::after{
    content:"●";
    position:absolute;
    right:0;
    /* level with the digit boxes */
    top: 70px;
    transform: translate(50%,-50%);
    font-size: 38px;
    line-height: 1;
    color:#000;
    pointer-events:none;
    z-index: 6;
  }

  /* Digit inputs */
  .cell{
    height: 100%;
    display:flex;
    align-items:flex-start;
    justify-content:center;
  }
  .digitInput{
    width: 86px;
    height: 96px;
    font-size: clamp(36px, 4.2vw, 62px);
    font-weight: 950;
    text-align:center;
    border-radius: 16px;
    border: 3px solid rgba(17,24,39,.85);
    outline:none;
    background: #ffffff;
    box-shadow: 0 10px 18px rgba(0,0,0,.08);
    caret-color: var(--accent);
  }
  .digitInput:focus{
    border-color: var(--accent);
    box-shadow: 0 12px 22px rgba(37,99,235,.18);
  }

  /* Overlay for animated digits and arrows */
  .overlay{
    position:absolute;
    inset:0;
    pointer-events:none;
  }
  .movingDigit{
    position:absolute;
    width: 86px;
    height: 96px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size: 56px;
    font-weight: 950;
    border-radius: 16px;
    border: 3px solid rgba(17,24,39,.90);
    background: #fff;
    box-shadow: 0 14px 28px rgba(0,0,0,.18);
    transition: transform 850ms cubic-bezier(.2,.9,.2,1);
    will-change: transform;
  }
  .arrowSvg{ position:absolute; inset:0; overflow: visible; }
  .arrowPath{
    fill:none;
    stroke: rgba(37,99,235,.70);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    marker-end: url(#arrowHead);
    stroke-dasharray: 7 8;
    animation: dash 850ms linear both;
  }
  @keyframes dash{ from{stroke-dashoffset: 70} to{stroke-dashoffset: 0} }

  @media (max-width: 900px){
    .sentence{ text-align:left; width:100%;}
    .pv tbody td{ height: 116px; }
    .digitInput, .resultBox, .movingDigit{ width: 70px; height: 80px; font-size: 46px; }
    .onesHead::after{ font-size: 28px; }
    .onesCell::after{ font-size: 32px; top: 60px; }
  }

  :root {
    --blue: #149bd7;
    --ink: #102131;
    --muted: #5c6b78;
    --paper: #fbfcfe;
    --panel: #ffffff;
    --line: #d8e2ea;
    --shadow: 0 12px 32px rgba(15, 33, 49, 0.12);
    --radius: 8px;
    --touch: 48px;
  }

  html,
  body {
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    background: #eef4f8;
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
    touch-action: manipulation;
  }

  body {
    overflow: hidden;
  }

  button,
  input,
  select {
    font: inherit;
  }

  button,
  select {
    min-height: var(--touch);
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
  }

  button {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  button:focus-visible,
  select:focus-visible,
  input:focus-visible {
    outline: 4px solid rgba(20, 155, 215, 0.35);
    outline-offset: 2px;
  }

  .app {
    display: grid;
    grid-template-rows: auto auto 1fr;
    height: 100vh;
    height: 100dvh;
    min-width: 320px;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(190px, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    background: #071018;
    color: #ffffff;
  }

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

  .brand img {
    width: 142px;
    height: auto;
    display: block;
    object-fit: contain;
    flex: 0 0 auto;
  }

  
  .brand-logo {
    display: inline-flex;
    border-radius: 6px;
  }

  .brand-logo:focus-visible {
    outline: 4px solid rgba(20, 155, 215, 0.35);
    outline-offset: 3px;
  }

  .home-button {
    min-height: var(--touch, 48px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    border: 2px solid #263d51;
    border-radius: 8px;
    background: #122436;
    color: #ffffff;
    text-decoration: none;
    font-weight: 800;
    white-space: nowrap;
  }

  .home-button:hover,
  .home-button:focus-visible {
    background: var(--blue, #149bd7);
    border-color: #8fd8f3;
    color: #06111a;
  }.title-block {
    min-width: 0;
  }

  h1 {
    margin: 0;
    font-size: clamp(1.35rem, 2vw, 2.05rem);
    line-height: 1.05;
    font-weight: 800;
  }
.top-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: end;
    flex-wrap: wrap;
  }

  .icon-button {
    width: var(--touch);
    padding: 0;
    display: inline-grid;
    place-items: center;
    background: #122436;
    color: #ffffff;
    border-color: #263d51;
  }

  .icon-button:hover,
  .icon-button[aria-pressed="true"] {
    background: var(--blue);
    border-color: #8fd8f3;
    color: #06111a;
  }

  .icon {
    width: 24px;
    height: 24px;
    display: block;
    pointer-events: none;
  }

  .toolbar {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(240px, auto);
    gap: 12px;
    align-items: center;
    padding: 12px 18px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
    z-index: 3;
  }

  .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    min-width: 0;
  }

  label {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
  }

  select {
    padding: 0 34px 0 12px;
    border-color: var(--line);
    background-color: #f8fbfd;
    font-weight: 800;
  }

  select:hover,
  button:hover {
    border-color: var(--blue);
    background-color: #e5f6fc;
  }

  button {
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-color: var(--line);
    background: #f8fbfd;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: none;
  }

  #calcBtn {
    background: var(--blue);
    border-color: var(--blue);
    color: #06111a;
  }

  #calcBtn:hover {
    border-color: #8fd8f3;
    background: #25aee7;
  }

  button.secondary {
    background: #f8fbfd;
    box-shadow: none;
  }

  .sentence {
    min-height: var(--touch);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fbfd;
    color: var(--ink);
    font-size: clamp(1rem, 1.6vw, 1.35rem);
    font-weight: 800;
    text-align: right;
  }

  .workspace {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 18px;
    background:
      linear-gradient(#dce8f0 1px, transparent 1px),
      linear-gradient(90deg, #dce8f0 1px, transparent 1px);
    background-size: 34px 34px;
  }

  .stage {
    min-width: calc(1290px * var(--view-zoom, 1));
    max-width: none;
    margin: 0 auto;
  }

  .workspace.is-fit .stage {
    min-width: 0;
    width: 100%;
    max-width: none;
  }

  .workspace.is-fit .digitInput,
  .workspace.is-fit .resultBox,
  .workspace.is-fit .movingDigit {
    width: min(86px, 3.8vw);
    height: min(96px, 4.7vw);
    font-size: min(62px, 2.45vw);
  }

  .workspace.is-fit .pv thead th {
    font-size: min(0.95rem, 1.05vw);
  }

  .gridWrap {
    margin-top: 0;
    position: relative;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  table.pv {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: #ffffff;
    border: 0;
    border-radius: 0;
  }

  .pv th,
  .pv td {
    border-right: 1px solid var(--line);
    text-align: center;
  }

  .pv th:last-child,
  .pv td:last-child {
    border-right: none;
  }

  .pv .hidden-column {
    display: none;
  }

  .pv thead th {
    height: 62px;
    padding: 6px 2px;
    border-bottom: 1px solid var(--line);
    background: #f8fbfd;
    color: var(--muted);
    font-size: clamp(0.72rem, 1.18vw, 1.05rem);
    font-weight: 800;
    white-space: nowrap;
    overflow: visible;
    position: relative;
    text-overflow: clip;
  }

  .pv tbody td {
    height: 132px;
    vertical-align: top;
    padding-top: 18px;
    position: relative;
  }

  .onesHead::after {
    content: "\25CF";
    font-size: 28px;
    color: var(--ink);
    z-index: 2;
  }

  .onesCell::after {
    content: "\25CF";
    font-size: 34px;
    color: var(--ink);
  }

  .digitInput,
  .resultBox {
    width: 86px;
    height: 96px;
    font-size: clamp(36px, 4.2vw, 62px);
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    border: 2px solid #aab8c3;
    background: #ffffff;
    color: var(--ink);
    box-shadow: 0 10px 20px rgba(15, 33, 49, 0.1);
    margin: 0 auto;
  }

  .digitInput {
    caret-color: var(--blue);
    text-align: center;
  }

  .digitInput:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px rgba(20, 155, 215, 0.18), 0 10px 20px rgba(15, 33, 49, 0.1);
  }

  .movingDigit {
    border-radius: var(--radius);
    border: 2px solid var(--blue);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: clamp(36px, 4.2vw, 62px);
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 14px 28px rgba(15, 33, 49, 0.18);
  }

  .arrowPath,
  .operationPath {
    stroke: rgba(20, 155, 215, 0.78);
  }

  .operationPath {
    fill: none;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    marker-end: url(#arrowHead);
  }

  .operationLabel {
    position: absolute;
    right: 36px;
    min-width: 64px;
    transform: translateY(-50%);
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 800;
    text-align: center;
    box-shadow: 0 8px 18px rgba(15, 33, 49, 0.12);
  }

  .instructions-dialog {
    width: min(820px, calc(100vw - 32px));
    max-height: min(780px, calc(100vh - 32px));
    border: 0;
    border-radius: var(--radius);
    padding: 0;
    color: var(--ink);
    background: #ffffff;
    box-shadow: 0 24px 70px rgba(6, 17, 26, 0.28);
  }

  .instructions-dialog::backdrop {
    background: rgba(6, 17, 26, 0.5);
  }

  .instructions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: #071018;
    color: #ffffff;
  }

  .instructions-header h2 {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.15;
  }

  .instructions-body {
    max-height: calc(min(780px, 100vh - 32px) - 76px);
    overflow: auto;
    padding: 16px 18px 20px;
    line-height: 1.45;
  }

  .instructions-body h3 {
    margin: 16px 0 8px;
    font-size: 1.05rem;
  }

  .instructions-body h3:first-child {
    margin-top: 0;
  }

  .instructions-body p,
  .instructions-body ul,
  .instructions-body ol {
    margin: 0 0 10px;
  }

  .instructions-body li {
    margin-bottom: 6px;
  }

  .instructions-body strong {
    color: #06111a;
  }

  @media (max-width: 900px) {
    body {
      overflow: auto;
    }

    .app {
      min-height: 100vh;
      height: auto;
    }

    .topbar,
    .toolbar {
      grid-template-columns: 1fr;
    }

    .top-actions {
      justify-content: start;
    }

    .sentence {
      justify-content: flex-start;
      text-align: left;
    }

    .workspace {
      padding: 12px;
    }

    .onesHead::after {
      font-size: 26px;
    }

    .onesCell::after {
      font-size: 30px;
      top: 60px;
    }
  }

  @media print {
    @page {
      size: landscape;
      margin: 12mm;
    }

    html,
    body {
      min-height: auto;
      overflow: visible;
      background: #ffffff;
    }

    .app {
      display: block;
      height: auto;
      min-width: 0;
    }

    .topbar {
      display: block;
      padding: 0 0 10px;
      background: #ffffff;
      color: var(--ink);
    }

    .brand {
      align-items: flex-start;
    }

    .brand img {
      width: 150px;
    }
.top-actions,
    .controls,
    .overlay,
    .instructions-dialog {
      display: none;
    }

    .toolbar {
      display: block;
      padding: 0 0 12px;
      border: 0;
      box-shadow: none;
    }

    .sentence {
      min-height: 0;
      justify-content: flex-start;
      padding: 0;
      border: 0;
      background: #ffffff;
      font-size: 18pt;
      text-align: left;
    }

    .sentence:empty::before {
      content: "Calculation:";
      color: var(--muted);
    }

    .workspace {
      overflow: visible;
      padding: 0;
      background: #ffffff;
    }

    .stage {
      min-width: 0;
      width: 100%;
      max-width: none;
      margin: 0;
    }

    .gridWrap {
      box-shadow: none;
      border-color: #8d9ba6;
      page-break-inside: avoid;
    }

    .pv thead th {
      height: 42px;
      font-size: 12pt;
      background: #f8fbfd;
    }

    .pv tbody td {
      height: 72px;
      padding-top: 10px;
    }

    .digitInput,
    .resultBox {
      width: 44px;
      height: 54px;
      font-size: 28pt;
      border: 1.5px solid #7f8d98;
      box-shadow: none;
    }

    .onesHead::after {
      font-size: 18px;
    }

    .onesCell::after {
      top: 37px;
      font-size: 22px;
    }
  }
