:root {
  color-scheme: light;
  --ink: #15365f;
  --ink-soft: #5b6f84;
  --paper: #fffefa;
  --yellow: #ffd84d;
  --yellow-soft: #fff3bd;
  --button-shadow: 4px 4px 0 rgba(21, 54, 95, .94);
  --panel-shadow: 5px 5px 0 rgba(21, 54, 95, .9);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  background-color: #eef9fc;
  background-image: linear-gradient(#7bd9f333 1px, transparent 1px), linear-gradient(90deg, #7bd9f333 1px, transparent 1px);
  background-size: 28px 28px;
}
[hidden] { display: none !important; }
button, input, summary { -webkit-tap-highlight-color: transparent; }
button {
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: 16px;
  font-weight: 1000;
  box-shadow: var(--button-shadow);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, opacity 150ms ease;
}
button:hover:not(:disabled) { transform: translate(-1px, -1px); background: var(--yellow-soft); box-shadow: 5px 5px 0 rgba(21,54,95,.94); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, summary:focus-visible, #tiles:focus-visible { outline: 3px solid #217fd3; outline-offset: 3px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 2px; color: var(--ink-soft); }
.quiet { font-size: 13px; padding: 0 14px; }
main { width: 100%; margin: auto; padding: 10px 18px 16px; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 30px; align-items: start; }
.map-panel { background: var(--paper); border: 2px solid var(--ink); border-radius: 18px; overflow: hidden; position: sticky; top: 10px; box-shadow: var(--panel-shadow); }
input { accent-color: var(--ink); }
/* Put touch ownership on the sized SVG root; an SVG <g> alone cannot stop native pan/pinch. */
#board { display: block; width: 100%; height: calc(100dvh - 30px); min-height: 430px; background: #f7f8ef; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#outline { fill: none; stroke: #c87c2c; stroke-width: 2.5; stroke-dasharray: 9 5; pointer-events: none; }
#dimensions { pointer-events: none; }
#dimensions path { fill: none; stroke: #a85b12; }
.dimension-extension { stroke-width: 1.5; stroke-dasharray: 4 3; }
.dimension-line { stroke-width: 2.5; }
#dimensions text { fill: #8a4407; font-size: 42px; font-weight: 800; text-anchor: middle; paint-order: stroke; stroke: var(--paper); stroke-width: 6px; stroke-linejoin: round; }
#tiles { touch-action: none; cursor: grab; }
#tiles:active { cursor: grabbing; }
.tile rect { fill: #3286e7; fill-opacity: .28; stroke: #206ecc; stroke-width: 2; vector-effect: non-scaling-stroke; }
.tile text { fill: #1459aa; paint-order: stroke; stroke: #fff; stroke-width: 3; stroke-linejoin: round; text-anchor: middle; pointer-events: none; font-size: 20px; font-weight: 650; }
.tile .dimension { font-size: 14px; stroke-width: 2; }
.tile .number { font-size: 13px; fill: #266ec1; }
#ruler path { fill: none; stroke: var(--ink); stroke-width: 3; }
#ruler text { font-size: 16px; text-anchor: middle; fill: var(--ink); paint-order: stroke; stroke: #fff; stroke-width: 3; }
aside { background: var(--paper); border: 2px solid var(--ink); border-radius: 18px; box-shadow: var(--panel-shadow); padding: 20px; }
h2 { font-size: 29px; line-height: 1.4; letter-spacing: 1px; margin: 12px 0 10px; }
.intro p { font-size: 13px; line-height: 1.9; color: var(--ink-soft); margin: 0 0 18px; }
.boundary-note { color: #a85b12; font-weight: 700; }
.unit-card { border: 2px solid var(--ink); background: #e9f7fc; border-radius: 14px; text-align: center; padding: 27px 15px 12px; }
.unit-square { width: 96px; height: 96px; position: relative; border: 2px solid #2871c6; background: #3485e72e; display: grid; place-items: center; margin: 0 auto; }
.unit-square strong { font-size: 31px; color: #2468b1; }
.unit-square strong span { font-size: 16px; margin-left: 4px; }
.side-label { position: absolute; bottom: calc(100% + 8px); font-size: 12px; line-height: 12px; color: #41709b; }
.vertical-label { position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); font-size: 12px; line-height: 12px; writing-mode: vertical-rl; letter-spacing: 1px; color: #41709b; }
.unit-card p { font-size: 11px; color: var(--ink-soft); margin: 14px 0 0; }
.primary { background: var(--yellow); font-size: 17px; width: 100%; margin-top: 18px; min-height: 52px; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.actions button { flex: 1; font-size: 13px; padding: 0 10px; }
#reset { background: #ffe8e0; }
.counter { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: 13px; color: var(--ink-soft); }
.counter strong { font-size: 28px; color: #246bdd; margin: 0 4px; }
.counter b { font-size: 19px; color: var(--ink); }
.hint { font-size: 12px; line-height: 1.8; color: var(--ink-soft); margin: 10px 0 20px; }
.think { border-top: 1px solid #b9cbd8; padding-top: 17px; }
.think p { font-size: 14px; line-height: 1.8; margin: 7px 0; }
small { font-size: 11px; line-height: 1.8; color: var(--ink-soft); }
details { font-size: 13px; line-height: 1.8; margin-top: 17px; border-top: 1px solid #b9cbd8; padding-top: 13px; }
summary { cursor: pointer; color: var(--ink); font-weight: 700; }
details p { margin: 10px 0; }
.answer-result { background: var(--yellow-soft); padding: 10px; border-radius: 9px; }
.answer-result strong { font-size: 20px; }
.scale { font-size: 12px; }
.scale summary { font-weight: 400; color: var(--ink-soft); }
@media (min-width: 1500px) { main { grid-template-columns: minmax(0, 1fr) 355px; gap: 40px; } }
@media (max-width: 760px) {
  main { padding: 10px 12px 25px; grid-template-columns: 1fr; gap: 18px; }
  .map-panel { position: relative; top: 0; border-radius: 16px; }
  #board { height: 58dvh; min-height: 370px; }
  aside { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px 12px; }
  .intro { grid-column: 1/-1; }
  .intro h2 { font-size: 24px; margin: 4px 0; }
  .intro h2 br { display: none; }
  .intro p { margin: 0; font-size: 13px; }
  .unit-card { grid-row: 2/5; padding: 28px 6px 12px; }
  .primary { margin-top: 0; align-self: start; font-size: 15px; padding: 0 6px; }
  .actions { margin: 0; gap: 7px; }
  .actions button { padding: 0 3px; font-size: 12px; }
  .counter { margin: 0; flex-wrap: wrap; gap: 4px; }
  .hint, .think, details { grid-column: 1/-1; margin: 0; }
  .hint { margin-bottom: 3px; }
  .unit-square { width: 78px; height: 78px; }
  .unit-card p { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } }

.view-tools { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.view-tools button { flex: 1; padding: 0 8px; }
.view-tools label { width: 100%; font-size: 12px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 760px) { .view-tools { grid-column: 1 / -1; margin: 0; } }

.add-tools { display: flex; gap: 10px; margin-top: 18px; }
.add-tools button { flex: 1; width: 0; margin: 0; min-height: 52px; padding: 0 5px; font-size: 14px; white-space: nowrap; }
#addSmall { background: #ffd9d5; }
#smallPicker { position: fixed; inset: auto; margin: 0; width: 290px; max-width: calc(100vw - 16px); padding: 16px; border: 2px solid var(--ink); border-radius: 16px; color: var(--ink); background: var(--paper); box-shadow: var(--panel-shadow); }
#smallPicker strong { font-size: 13px; }
.small-options { display: flex; gap: 10px; margin-top: 14px; }
.small-options button { flex: 1; padding: 0 8px; background: #ffd9d5; }
#smallPicker p { font-size: 12px; line-height: 1.7; margin: 14px 0 0; }
.small-status { margin-top: 14px; color: #ac3734; font-size: 13px; line-height: 1.8; font-weight: 700; }
#clearSmall { min-height: 36px; margin-top: 8px; font-size: 12px; }
.small-tiles .small-tile { vector-effect: non-scaling-stroke; fill: #ef4444; fill-opacity: .42; stroke: #b93232; stroke-width: 1; }
.small-tiles .small-number { text-anchor: middle; paint-order: stroke; pointer-events: none; fill: #8a1e1e; font-size: 10px; stroke: #fff; stroke-width: 1.5px; font-weight: 700; }
@media (max-width: 760px) {
  .add-tools, .small-status, #clearSmall { grid-column: 1 / -1; }
  .add-tools { margin: 0; }
  .unit-card { grid-row: auto; grid-column: 1 / -1; }
  .actions, .counter { grid-column: 1 / -1; }
}

/* Additional reference only: keep the existing hectare diagram in place. */
.mini-unit-square { position: absolute; width: 9.6px; height: 9.6px; right: -59px; top: calc(50% - 4.8px); border: 1px solid #b93232; background: #ef44446b; }
.mini-unit-square span { position: absolute; color: #ac3734; font-size: 10px; line-height: 1; font-weight: 400; white-space: nowrap; }
.mini-top { bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%); }
.mini-right { left: calc(100% + 7px); top: 50%; transform: translateY(-50%); writing-mode: vertical-rl; }
@media (max-width: 760px) { .mini-unit-square { width: 7.8px; height: 7.8px; right: -50px; top: calc(50% - 3.9px); } }

/* Shift the hectare reference as a unit; keep the red reference in its space. */
.unit-square { transform: translateX(-32px); }
.unit-card > p { transform: translateX(-24px); }
.mini-unit-square { right: -75px; }
.mini-unit-square .mini-formula { top: calc(100% + 16px); right: -35px; left: auto; line-height: 1.5; text-align: right; white-space: nowrap; }
@media (max-width: 760px) { .mini-unit-square { right: -66px; } }
@media (max-width: 760px) { .mini-unit-square .mini-formula { right: -45px; } }
