/* Dálkareikningur: column addition and subtraction */
body { overflow: hidden; }

#app {
  position: fixed; left: calc(var(--sl) + 16px); right: calc(var(--sr) + 16px);
  top: calc(var(--st) + 72px); bottom: calc(var(--sb) + 118px);
  display: grid; grid-template-columns: minmax(300px, 36%) 1fr; gap: 18px;
}
.left { display: flex; flex-direction: column; gap: 14px; min-height: 0; }

/* ---- the written sum, laid out like the book ---- */
.written {
  background: var(--card); border-radius: 26px; box-shadow: 0 8px 28px rgba(31, 42, 68, 0.1);
  padding: 18px 24px 20px; display: flex; justify-content: center;
}
.wgrid {
  display: grid; justify-content: center; align-items: end; column-gap: 4px;
  font-size: clamp(40px, 5vw, 62px); font-weight: 700; line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.wgrid .cell { width: 0.72em; text-align: center; position: relative; border-radius: 10px; }
.wgrid .cell.cur { background: rgba(79, 107, 237, 0.08); }
.wgrid .opcell { color: var(--muted); width: 0.7em; text-align: center; }
.wgrid .mark { font-size: 0.42em; min-height: 1.15em; line-height: 1.15; display: flex; align-items: flex-end; justify-content: center; }
.wgrid .mark.carry { color: #e09a00; }
.wgrid .mark.borrow { color: var(--minus); }
.wgrid .crossed { color: #b9bfcb; text-decoration: line-through; text-decoration-color: var(--minus); text-decoration-thickness: 0.08em; }
.wgrid .rule { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: var(--ink); margin: 4px 0 6px; }
.wgrid .ans {
  width: 0.72em; height: 1.1em; box-sizing: border-box; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; color: var(--accent);
}
.wgrid .ans.todo { border: 3px dashed #d4d9e3; }
.wgrid .ans.cur { border: 3px dashed var(--accent); background: rgba(79, 107, 237, 0.06); }
.wgrid .ans.filled { animation: wpop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }
.wgrid .ans.faint { color: #c3c9d4; }
.wgrid .ans.shake { animation: wshake 0.4s; }

.ctip { font-size: 20px; font-weight: 600; color: #5d667a; text-align: center; padding: 0 6px; line-height: 1.35; }
.ctip b { color: var(--accent); }
.ctip.good { color: var(--plus); font-size: 26px; }

/* ---- the place-value board ---- */
.board { display: flex; gap: 10px; min-height: 0; }
.pcol {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column;
  background: var(--card); border-radius: 22px; box-shadow: 0 4px 14px rgba(31, 42, 68, 0.08);
  border: 3px solid transparent; cursor: pointer; transition: border-color 0.2s, opacity 0.2s, background 0.2s;
}
.pcol.cur { border-color: var(--accent); box-shadow: 0 8px 24px rgba(79, 107, 237, 0.2); }
.pcol.done { opacity: 0.55; }
.pcol.nudge { animation: wshake 0.4s; }
.phead { text-align: center; font-size: 15px; font-weight: 700; color: var(--muted); padding: 8px 4px 2px; }
.pcol.cur .phead { color: var(--accent); }
.parea { flex: 1 1 0; min-height: 0; display: flex; flex-wrap: wrap; align-content: flex-end; justify-content: center; gap: 5px; padding: 8px; }
.pbot { flex: 0.75 1 0; align-content: flex-start; border-top: 3px dashed #e3e7ef; position: relative; }
.pbot::before { content: attr(data-op); position: absolute; left: 6px; top: 2px; font-size: 22px; font-weight: 700; color: #c3c9d4; }
.pfoot { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 6px 10px; min-height: 52px; justify-content: center; }
.pfoot .bundle {
  font: inherit; font-size: 15px; font-weight: 700; border: none; border-radius: 12px; padding: 8px 10px; cursor: pointer;
  background: #fff3c4; color: #7a5a00; box-shadow: 0 0 0 3px #f2b200; animation: glow 1.4s ease-in-out infinite;
}

/* blocks: 10000 berry, 1000 purple, 100 green, 10 navy, 1 grey (as on the balance scale) */
.blk { flex: none; border-radius: 4px; box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.16); }
.blk.b10000 { width: 40px; height: 40px; background: #a8326e; border-radius: 6px; }
.blk.b1000 { width: 34px; height: 34px; background: #7b52d9; border-radius: 5px; }
.blk.b100 { width: 30px; height: 30px; background: #12a37a; }
.blk.b10 { width: 11px; height: 32px; background: #2b3a5e; border-radius: 3px; }
.blk.b1 { width: 14px; height: 14px; background: #8f9bb3; border-radius: 3px; }
.blk.ghost { background: transparent; box-shadow: none; border: 3px dashed #ef8a8a; box-sizing: border-box; }
.blk.carry { outline: 3px solid #f2b200; outline-offset: 2px; }
.blk.breakable { cursor: pointer; animation: breakme 1.4s ease-in-out infinite; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#fx .blk { position: fixed; }

/* ---- the 0-9 pad ---- */
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.bar .group:first-child { justify-self: start; }
.bar .group:last-child { justify-self: end; }
.pad { display: flex; gap: 8px; pointer-events: auto; padding: 10px; border-radius: 22px; background: var(--card); box-shadow: 0 4px 14px rgba(31, 42, 68, 0.1); }
.pad button {
  width: 58px; height: 70px; border: none; border-radius: 16px; cursor: pointer;
  font: inherit; font-size: 34px; font-weight: 700; color: #fff; background: var(--accent);
  transition: transform 0.1s, opacity 0.2s;
}
.pad button:active { transform: scale(0.92); }
.pad button:disabled { opacity: 0.25; cursor: default; }
.pad.shake { animation: wshake 0.4s; }

/* ---- making a problem ---- */
.bcard { width: min(640px, 94vw); }
.opseg button { height: 52px; font-size: 19px; }
.brows { display: flex; flex-direction: column; gap: 14px; }
.brow { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.blabel { font-size: 18px; font-weight: 600; color: var(--muted); min-width: 130px; }
.blabel .bop { color: var(--ink); font-size: 24px; }
.steppers { display: flex; gap: 8px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 4px; background: #f6f7fa; border-radius: 16px; padding: 6px; width: 78px; }
.step .sname { font-size: 12px; font-weight: 600; color: var(--muted); }
.step button {
  width: 100%; height: 40px; border: none; border-radius: 12px; cursor: pointer;
  font: inherit; font-size: 24px; font-weight: 700; color: var(--ink); background: #fff; box-shadow: 0 2px 6px rgba(31, 42, 68, 0.08);
}
.step button:disabled { opacity: 0.3; cursor: default; }
.step .sval { font-size: 36px; font-weight: 700; line-height: 1; }
.step .sval.lead { color: #c3c9d4; }
.bmsg { min-height: 1.3em; font-size: 17px; font-weight: 600; color: var(--minus); }
.bactions { display: flex; justify-content: flex-end; gap: 10px; }

@keyframes wpop { 0% { transform: scale(0.5); } 100% { transform: scale(1); } }
@keyframes wshake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 3px #f2b200; } 50% { box-shadow: 0 0 0 6px rgba(242, 178, 0, 0.45); } }
@keyframes breakme { 50% { transform: translateY(-3px); box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.16), 0 0 0 3px #f2b200; } }

/* portrait iPad / narrow: the written sum above the board */
@media (max-width: 900px), (orientation: portrait) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .pad button { width: 48px; height: 60px; font-size: 28px; }
  #newBtn { width: 56px; padding: 0; }
  #newBtn span { display: none; }
  #newBtn::before { content: "✏️"; font-size: 24px; }
}
@media (max-width: 600px) {
  .pad { gap: 4px; padding: 6px; }
  .pad button { width: 30px; height: 50px; font-size: 22px; border-radius: 10px; }
}
#newBtn { white-space: nowrap; }
.blk.out { opacity: 0.7; outline: 3px solid #ef8a8a; outline-offset: 1px; }
body.busy #board, body.busy #pad { pointer-events: none; }
