:root {
  --bg: #efe3cc;
  --panel: rgba(255, 248, 238, 0.92);
  --line: rgba(138, 102, 63, 0.18);
  --ink: #412a18;
  --muted: #7e6549;
  --wood-1: #dfbb83;
  --wood-2: #c99457;
  --wood-3: #9d6834;
  --accent: #6c8d69;
  --warn: #b96a3f;
  --soft: #f7efe3;
  --shadow: 0 18px 34px rgba(98, 68, 39, 0.14);
  --unit-width: 264px;
  --block-height: 66px;
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at left top, rgba(255, 245, 220, 0.9), transparent 32%),
    linear-gradient(180deg, #efdfc6 0%, #eadcc8 40%, #e5d2ba 100%);
}

button {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 16px 12px 28px;
}

.topbar,
.lesson-head,
.lesson-actions,
.status-grid,
.work-head,
.zone-head,
.recipient-head,
.course-grid,
.tool-row {
  display: flex;
  gap: 10px;
}

.topbar,
.lesson-head,
.work-head,
.zone-head,
.recipient-head {
  align-items: center;
  justify-content: space-between;
}

.eyebrow,
.mini-label,
.zone-meta,
.helper-copy {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 6vw, 42px);
  line-height: 1.05;
}

h2 {
  font-size: clamp(20px, 4vw, 28px);
}

h3 {
  font-size: 17px;
}

.course-card,
.lesson-card,
.guide-card,
.workspace,
.zone,
.recipient,
.reference-card,
.free-lab,
.piece-bank {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.course-card,
.lesson-card,
.guide-card,
.workspace,
.free-lab {
  padding: 16px;
}

.course-card,
.lesson-card,
.guide-card {
  margin-bottom: 14px;
}

.course-grid {
  margin-top: 10px;
  flex-wrap: wrap;
}

.course-button,
.secondary-button,
.primary-button,
.context-button,
.inline-button,
.back-link {
  border: 1px solid rgba(117, 85, 51, 0.16);
  border-radius: 999px;
  min-height: 44px;
  padding: 0 14px;
  background: rgba(255, 252, 246, 0.95);
  color: var(--ink);
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.course-button.active,
.primary-button {
  background: linear-gradient(180deg, #7f5c3c, #65472b);
  color: #fff8ee;
  border-color: transparent;
}

.free-lab-button {
  margin-top: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  text-decoration: underline;
}

.lesson-actions {
  flex-wrap: wrap;
}

.emphasis-copy {
  font-weight: 800;
}

.instruction {
  margin-top: 10px;
  line-height: 1.7;
}

.status-grid {
  margin-top: 14px;
  flex-wrap: wrap;
}

.status-card {
  flex: 1 1 240px;
  min-height: 88px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 251, 244, 0.9);
  border: 1px solid rgba(134, 103, 70, 0.12);
}

.guide-card {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.guide-step {
  flex: 1 1 180px;
  min-height: 52px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255, 250, 241, 0.95);
  border: 1px dashed rgba(116, 90, 62, 0.24);
}

.problem-area {
  display: grid;
  gap: 14px;
}

.helper-banner,
.success-card {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 250, 241, 0.94);
  border: 1px solid rgba(124, 90, 53, 0.14);
}

.success-card {
  display: grid;
  gap: 10px;
}

.workspace {
  display: grid;
  gap: 14px;
}

.work-grid,
.recipient-grid,
.calc-grid {
  display: grid;
  gap: 14px;
}

.work-grid.two,
.calc-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.work-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.zone,
.recipient,
.piece-bank,
.reference-card,
.free-lab {
  padding: 12px;
}

.zone-body,
.recipient-body {
  position: relative;
  min-height: 118px;
  padding: 12px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 251, 244, 0.92), rgba(239, 226, 206, 0.78)),
    repeating-linear-gradient(90deg, rgba(124, 90, 53, 0.08) 0 16px, rgba(255, 255, 255, 0) 16px 32px);
  overflow-x: auto;
}

.zone-body.drop-hover,
.recipient-body.drop-hover {
  outline: 3px solid rgba(108, 141, 105, 0.36);
}

.scroll-hint {
  scrollbar-width: thin;
}

.track {
  position: relative;
  min-height: var(--block-height);
  min-width: calc(var(--unit-width) + 36px);
}

.track.equal-target {
  min-width: unset;
}

.target-outline {
  position: absolute;
  top: 0;
  left: 0;
  height: var(--block-height);
  border-radius: 18px;
  border: 2px dashed rgba(126, 100, 72, 0.34);
  background: rgba(126, 100, 72, 0.05);
}

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

.zone-meta {
  margin-top: 8px;
  min-height: 20px;
}

.fraction-block-hit {
  position: absolute;
  top: 0;
  min-width: 44px;
  height: calc(var(--block-height) + 10px);
  padding-top: 5px;
  cursor: pointer;
  touch-action: none;
}

.fraction-block {
  position: absolute;
  top: 5px;
  left: 0;
  height: var(--block-height);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 243, 220, 0.5), rgba(255, 255, 255, 0) 20%),
    linear-gradient(180deg, var(--wood-1), var(--wood-2));
  border: 1px solid rgba(120, 84, 48, 0.38);
  box-shadow:
    inset 0 1px 0 rgba(255, 250, 242, 0.66),
    inset 0 -8px 14px rgba(115, 74, 33, 0.1),
    0 10px 14px rgba(101, 68, 39, 0.16);
  overflow: hidden;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.fraction-block::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(130, 90, 48, 0.06) 0 8%, rgba(255, 255, 255, 0) 8% 18%, rgba(130, 90, 48, 0.05) 18% 24%, rgba(255, 255, 255, 0) 24% 38%, rgba(126, 88, 44, 0.05) 38% 46%, rgba(255, 255, 255, 0) 46% 58%, rgba(126, 88, 44, 0.05) 58% 68%, rgba(255, 255, 255, 0) 68% 82%, rgba(130, 90, 48, 0.06) 82% 88%, rgba(255, 255, 255, 0) 88%);
  mix-blend-mode: multiply;
}

.fraction-block.selected {
  outline: 3px solid rgba(108, 141, 105, 0.42);
  transform: translateY(-5px);
}

.fraction-block.invalid {
  animation: invalidShake 280ms ease;
}

.fraction-block.targetable {
  outline: 3px dashed rgba(185, 106, 63, 0.48);
  animation: targetBlink 1s ease-in-out infinite;
}

.fraction-block.dragging {
  transform: translateY(-8px) scale(1.03);
  box-shadow:
    inset 0 1px 0 rgba(255, 250, 242, 0.66),
    inset 0 -8px 14px rgba(115, 74, 33, 0.1),
    0 24px 28px rgba(83, 57, 31, 0.28);
}

.fraction-block.fracturing {
  animation: fractureLift 460ms ease;
}

.fraction-block.fracturing::after {
  content: "";
  position: absolute;
  inset: 8px;
  background: repeating-linear-gradient(90deg, rgba(95, 63, 33, 0) 0 32%, rgba(95, 63, 33, 0.58) 32% 34%, rgba(95, 63, 33, 0) 34% 100%);
  animation: fractureLines 460ms ease;
}

.fraction-block.mergeing {
  animation: mergePulse 360ms ease;
}

@keyframes fractureLift {
  0% { transform: translateY(0) rotate(0deg); }
  20% { transform: translateY(-7px) rotate(-0.4deg); }
  52% { transform: translateY(-7px) rotate(0.6deg); }
  70% { transform: translateY(-4px) rotate(-0.3deg); }
  100% { transform: translateY(0) rotate(0deg); }
}

@keyframes fractureLines {
  0% { opacity: 0; transform: scaleY(0.6); }
  45% { opacity: 1; transform: scaleY(1); }
  100% { opacity: 0; }
}

@keyframes mergePulse {
  0% { transform: translateX(0); }
  40% { transform: translateX(-3px); }
  75% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

@keyframes invalidShake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

@keyframes targetBlink {
  0% { box-shadow: 0 0 0 rgba(185, 106, 63, 0); }
  50% { box-shadow: 0 0 0 6px rgba(185, 106, 63, 0.08); }
  100% { box-shadow: 0 0 0 rgba(185, 106, 63, 0); }
}

.block-content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #4b2f13;
  font-weight: 700;
}

.tick-layer {
  position: absolute;
  inset: 6px 8px;
  display: flex;
}

.tick-layer span {
  flex: 1;
  border-right: 1px solid rgba(109, 73, 35, 0.24);
}

.tick-layer span:last-child {
  border-right: 0;
}

.fraction {
  display: inline-grid;
  justify-items: center;
  align-items: center;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.fraction .bar {
  width: 1.5em;
  height: 2px;
  margin: 2px 0;
  border-radius: 99px;
  background: currentColor;
}

.fraction.whole .bar,
.fraction.whole .bottom {
  display: none;
}

.fraction.small {
  transform: scale(0.84);
}

.reference-card {
  display: grid;
  gap: 10px;
}

.reference-line {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  padding: 10px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.98);
  box-shadow: 0 18px 28px rgba(77, 53, 28, 0.24);
}

.context-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.context-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.context-button,
.inline-button {
  min-height: 40px;
}

.recipient-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.recipient {
  display: grid;
  gap: 10px;
}

.recipient-total {
  color: var(--muted);
  font-size: 13px;
}

.piece-bank {
  display: grid;
  gap: 10px;
}

.piece-count {
  color: var(--muted);
  font-size: 14px;
}

.tool-row {
  flex-wrap: wrap;
}

.action-row {
  margin-top: -2px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .lesson-head,
  .topbar,
  .work-head,
  .zone-head {
    flex-direction: column;
    align-items: stretch;
  }

  .work-grid.two,
  .work-grid.three,
  .calc-grid,
  .recipient-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  :root {
    --unit-width: 214px;
    --block-height: 60px;
  }

  .app {
    padding: 12px 10px 24px;
  }

  .course-button,
  .secondary-button,
  .primary-button,
  .context-button,
  .inline-button,
  .back-link {
    min-height: 48px;
  }
}
