*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #2a241c;
  --ink: #f6efe2;
  --muted: #b0a494;
  --persimmon: #c85838;
  --ginkgo: #d4a838;
  --indigo: #3a5888;
  --kinari: #ebe4d4;
  --wood: #7a5230;
  --mint: #5ee0b8;
}

html {
  font-family: "Hiragino Mincho ProN", "Hiragino Sans", Meiryo, serif;
  background: var(--bg);
  color: var(--ink);
}

body {
  margin: 0;
  min-height: 100dvh;
  position: relative;
}

.workshop-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(165deg, #3d3228 0%, #241c16 45%, #1a1410 100%);
  pointer-events: none;
}

.workshop-window {
  position: absolute;
  top: 4%;
  right: 6%;
  width: min(36vw, 160px);
  height: min(22vw, 100px);
  border: 4px solid #4a3424;
  background: linear-gradient(145deg, rgba(255, 230, 190, 0.22), rgba(120, 160, 200, 0.08));
  box-shadow: inset 0 0 24px rgba(255, 220, 160, 0.25);
}

.workshop-window::before,
.workshop-window::after {
  content: "";
  position: absolute;
  background: #4a3424;
}

.workshop-window::before {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 3px;
  transform: translateX(-50%);
}

.workshop-window::after {
  top: 50%;
  left: 0;
  right: 0;
  height: 3px;
  transform: translateY(-50%);
}

.workshop-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 55% 40% at 78% 12%, rgba(255, 210, 140, 0.2), transparent 65%);
  opacity: 0.65;
  transition: opacity 1.2s ease;
}

body.is-complete .workshop-glow {
  opacity: 1;
}

.masthead {
  padding: 10px 14px;
  position: relative;
  z-index: 1;
}

.back {
  color: var(--mint);
  text-decoration: none;
  font-weight: 700;
  font-family: "Hiragino Sans", sans-serif;
}

.back:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 12px 28px;
  position: relative;
  z-index: 1;
}

.hero h1 {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 5vw, 1.85rem);
  line-height: 1.15;
}

.hero h1 span {
  display: block;
}

.kicker {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  color: #d8a878;
  font-family: ui-monospace, Menlo, monospace;
}

.catch,
.hint {
  margin: 8px 0;
  font-size: 0.92rem;
  color: var(--muted);
  font-family: "Hiragino Sans", sans-serif;
}

.banner {
  margin: 8px 0;
  padding: 8px 10px;
  background: rgba(200, 88, 56, 0.18);
  border-left: 3px solid var(--persimmon);
  font-size: 0.9rem;
  font-family: "Hiragino Sans", sans-serif;
}

.stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.loom-shell {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 8px;
  align-items: stretch;
  padding: 10px 6px;
  background: linear-gradient(180deg, rgba(90, 60, 36, 0.35), rgba(40, 28, 18, 0.5));
  border: 3px solid #5c3a24;
  border-radius: 12px;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 220, 180, 0.15);
}

.spools {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 10px;
}

.spool {
  position: relative;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
}

.spool-visual {
  display: block;
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid var(--kinari);
  box-shadow:
    inset 0 -4px 8px rgba(0, 0, 0, 0.25),
    0 3px 6px rgba(0, 0, 0, 0.35);
}

.spool[data-color="persimmon"] .spool-visual {
  background: radial-gradient(circle at 35% 30%, #e87850, var(--persimmon) 55%, #8a3020);
}
.spool[data-color="ginkgo"] .spool-visual {
  background: radial-gradient(circle at 35% 30%, #f0d060, var(--ginkgo) 55%, #a07818);
}
.spool[data-color="indigo"] .spool-visual {
  background: radial-gradient(circle at 35% 30%, #5a78a8, var(--indigo) 55%, #243858);
}

.spool-label {
  display: block;
  margin-top: 2px;
  font-size: 0.65rem;
  font-weight: 800;
  text-align: center;
  color: var(--kinari);
  font-family: "Hiragino Sans", sans-serif;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.spool.is-active .spool-visual {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}

.spool.is-disabled {
  opacity: 0.32;
  pointer-events: none;
  cursor: not-allowed;
}

.spool.is-spinning .spool-visual {
  animation: spool-spin 0.55s ease-out;
}

@keyframes spool-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(320deg);
  }
}

.spool:focus-visible .spool-visual {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}

#loom-canvas {
  width: 100%;
  height: auto;
  border-radius: 4px;
  touch-action: none;
  box-shadow: inset 0 0 0 2px rgba(90, 60, 36, 0.6);
}

.assistant {
  margin: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-left: 4px;
}

.assistant figcaption {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: "Hiragino Sans", sans-serif;
}

.burapi {
  display: block;
  width: 72px;
  height: auto;
  filter: drop-shadow(4px 8px 6px rgba(0, 0, 0, 0.45));
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.toolbar button,
.btn-save,
.btn-reset-storage {
  font: inherit;
  font-family: "Hiragino Sans", sans-serif;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #6a5848;
  background: linear-gradient(180deg, #4a4038, #322820);
  color: var(--ink);
  cursor: pointer;
}

.toolbar button:disabled,
.btn-save:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toolbar button:focus-visible,
.btn-save:focus-visible,
.btn-reset-storage:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

.storage-info {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
  font-family: "Hiragino Sans", sans-serif;
}

.result {
  margin-top: 12px;
  padding: 14px;
  border: 2px solid #8a6848;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(50, 40, 30, 0.92), rgba(28, 22, 16, 0.95));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.result.is-reveal {
  animation: spread 0.9s ease-out;
}

.weave-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: #f0d8a8;
}

.weave-stats {
  color: var(--muted);
  font-size: 0.9rem;
  font-family: "Hiragino Sans", sans-serif;
}

.fabric-wrap {
  position: relative;
  max-width: 240px;
  margin: 12px 0;
}

#fabric-preview {
  width: 100%;
  display: block;
  border: 4px solid #e8dcc8;
  border-radius: 2px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.fabric-fringe {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -6px;
  height: 14px;
  background: repeating-linear-gradient(
    90deg,
    var(--persimmon) 0 6px,
    var(--ginkgo) 6px 12px,
    var(--indigo) 12px 18px
  );
  opacity: 0.75;
  transform-origin: top center;
  animation: fringe-sway 2.8s ease-in-out infinite;
}

@keyframes fringe-sway {
  0%,
  100% {
    transform: rotate(-1.5deg) skewX(-2deg);
  }
  50% {
    transform: rotate(1.5deg) skewX(2deg);
  }
}

.btn-save {
  width: 100%;
  font-weight: 800;
  background: linear-gradient(180deg, #e8c8a0, #a87848);
  color: #2a1810;
  border: none;
}

html[data-capture="1"] .capture-hide {
  display: none !important;
}

html[data-capture="1"] .app {
  max-width: 390px;
}

html[data-promo-shot="1"] .capture-hide {
  display: none !important;
}

html[data-promo-shot="1"] .app {
  max-width: 390px;
}

@keyframes spread {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .result.is-reveal {
    animation: none;
  }
  .fabric-fringe {
    animation: none;
    opacity: 0.85;
  }
  .spool.is-spinning .spool-visual {
    animation: none;
    filter: brightness(1.15);
  }
}
