:root {
  --paper: #fffaf0;
  --paper-deep: #f7e7c6;
  --panel: #fffdfa;
  --shelf: #fff4d9;
  --ink: #2b251d;
  --muted: #736651;
  --line: #dfc895;
  --green: #4f8f63;
  --green-deep: #2f6844;
  --green-dark: #183b29;
  --gold: #e7bb52;
  --gold-deep: #bd8628;
  --danger: #a8493d;
  --white: #ffffff;
  --radius: 8px;
  --shadow: 0 12px 30px rgba(45, 51, 35, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(47, 104, 68, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 28px;
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.7;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--green-deep);
}

[hidden] {
  display: none !important;
}

.loom-skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--green-dark);
  color: var(--white);
  transform: translateY(-160%);
}

.loom-skip-link:focus {
  transform: translateY(0);
}

.site-header {
  border-bottom: 1px solid rgba(223, 200, 149, 0.9);
  background: rgba(255, 253, 250, 0.96);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  width: min(1320px, calc(100% - 32px));
  min-height: 58px;
  margin: 0 auto;
}

.site-logo {
  flex: 0 0 auto;
  color: var(--green-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.035em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.site-nav a {
  flex: 0 0 auto;
  padding: 7px 9px;
  border-radius: 5px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.site-nav a:hover {
  background: var(--shelf);
  color: var(--green-deep);
}

.site-logo:focus-visible,
.site-nav a:focus-visible,
.site-footer a:focus-visible,
.loom-related a:focus-visible,
.loom-button:focus-visible,
.loom-form input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.page-shell {
  display: grid;
  grid-template-columns: 110px minmax(0, 1100px) 110px;
  gap: 20px;
  justify-content: center;
  width: min(1360px, calc(100% - 32px));
  margin: 18px auto 42px;
}

.main-content {
  min-width: 0;
}

.main-content:focus {
  outline: none;
}

.ad-rail {
  align-self: stretch;
}

.ad-placeholder {
  position: sticky;
  top: 18px;
  display: grid;
  min-height: 300px;
  place-content: center;
  gap: 6px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.ad-placeholder span {
  color: var(--gold-deep);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.ad-placeholder strong {
  font-size: 11px;
  font-weight: 700;
  writing-mode: vertical-rl;
}

.loom-hero {
  margin: 0 0 14px;
  padding: 12px 4px 4px;
}

.loom-kicker,
.loom-eyebrow {
  margin: 0 0 4px;
  color: var(--green-deep);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.17em;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 1000px;
  margin: 0;
  color: var(--green-dark);
  font-family: Georgia, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(30px, 4.1vw, 46px);
  line-height: 1.16;
  letter-spacing: 0.015em;
}

h2,
h3 {
  margin: 0;
  color: var(--green-dark);
  line-height: 1.35;
}

h2 {
  font-size: clamp(21px, 2.8vw, 28px);
}

h3 {
  font-size: 20px;
}

.loom-hero__rule {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

.loom-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 250, 0.97);
  box-shadow: var(--shadow);
}

.loom-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  margin-bottom: 18px;
  padding: 20px 22px;
}

.loom-intro p:not(.loom-eyebrow, .loom-start-failure) {
  margin: 7px 0 0;
  color: var(--muted);
}

.loom-intro__action {
  min-width: 170px;
  text-align: center;
}

.loom-button {
  min-height: 44px;
  padding: 9px 18px;
  border: 1px solid var(--green-deep);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 900;
}

.loom-button--primary {
  background: var(--green-deep);
  color: var(--white);
  box-shadow: 0 4px 0 var(--green-dark);
}

.loom-button--primary:hover {
  background: var(--green-dark);
}

.loom-button:active {
  box-shadow: none;
  transform: translateY(2px);
}

.loom-button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.loom-start-failure {
  max-width: 320px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

.loom-game {
  margin-bottom: 18px;
  padding: 16px 18px 18px;
}

.loom-game__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.loom-phase-status {
  flex: 0 0 auto;
  margin: 0;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--shelf);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 900;
}

.loom-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 8px;
}

.loom-metrics div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
}

.loom-metrics span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.loom-metrics strong {
  color: var(--green-dark);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.loom-progress {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--paper-deep);
}

.loom-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green-deep), var(--gold));
  transition: width 180ms ease-out;
}

.loom-game__body {
  display: grid;
  grid-template-columns: minmax(250px, 0.78fr) minmax(0, 1.22fr);
  gap: 16px;
  margin-top: 14px;
}

.loom-stage {
  min-width: 0;
  margin: 0;
  padding: 10px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 10%, rgba(231, 187, 82, 0.2), transparent 45%),
    var(--paper);
}

.loom-stage figcaption {
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 900;
}

.loom-frame {
  position: relative;
  width: min(100%, 390px);
  margin: 2px auto 0;
}

.loom-frame__svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 247px;
}

.loom-svg__wood {
  fill: #9a6b3c;
  stroke: #664627;
  stroke-width: 3;
}

.loom-svg__threads line {
  stroke: #cbb481;
  stroke-width: 2;
}

.loom-svg__fabric rect {
  fill: var(--green);
  stroke: var(--green-deep);
  stroke-width: 1.5;
  opacity: 0.05;
  transition: opacity 140ms ease-out;
}

.loom-svg__fabric rect:nth-child(even) {
  fill: var(--gold);
  stroke: var(--gold-deep);
}

.loom-svg__fabric rect.is-woven {
  opacity: 0.96;
}

.loom-shuttle {
  --loom-row-index: 0;
  position: absolute;
  top: calc(77% - (var(--loom-row-index) * 8.55%));
  left: 17%;
  display: none;
  width: 54px;
  height: 12px;
  border: 2px solid var(--green-dark);
  border-radius: 70% 15% 70% 15%;
  background: var(--gold);
  box-shadow: 0 2px 0 rgba(24, 59, 41, 0.18);
}

.loom-shuttle::after {
  position: absolute;
  top: 3px;
  right: 9px;
  width: 20px;
  height: 2px;
  background: var(--green-dark);
  content: "";
}

.loom-shuttle.is-running {
  display: block;
}

.loom-shuttle.is-running.is-left-to-right {
  animation: loom-shuttle-right 280ms ease-in-out both;
}

.loom-shuttle.is-running.is-right-to-left {
  animation: loom-shuttle-left 280ms ease-in-out both;
}

@keyframes loom-shuttle-right {
  from { left: 17%; }
  to { left: 70%; }
}

@keyframes loom-shuttle-left {
  from { left: 70%; }
  to { left: 17%; }
}

#loom-weave-summary {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.loom-controls {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.loom-pattern {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.loom-pattern__heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.loom-pattern__badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--green-dark);
  color: var(--white);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.09em;
}

.loom-pattern__help {
  margin: 5px 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.loom-pattern__groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.loom-pattern__group {
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
}

.loom-pattern__group > span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.loom-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 29px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.loom-chips li {
  max-width: 100%;
  padding: 3px 6px;
  border: 1px solid var(--green);
  border-radius: 4px;
  background: var(--white);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.loom-chips li.loom-chip--blank {
  min-width: 31px;
  border: 2px dashed var(--gold-deep);
  background: #fff8dc;
  color: var(--gold-deep);
  text-align: center;
}

.loom-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--shelf);
}

.loom-form > label {
  display: block;
  margin-bottom: 5px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 900;
}

.loom-form__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.loom-form input {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 8px 11px;
  border: 2px solid var(--green-deep);
  border-radius: 6px;
  background: var(--white);
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.loom-form input:disabled {
  background: var(--paper-deep);
  color: var(--muted);
}

.loom-input-hint {
  min-height: 21px;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.loom-input-hint.is-error {
  color: var(--danger);
}

.loom-result {
  margin-top: 14px;
  padding: 15px;
  border: 2px solid var(--green-deep);
  border-radius: 6px;
  background: var(--shelf);
}

.loom-result__numbers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.loom-result__numbers p {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--white);
}

.loom-result__numbers span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.loom-result__numbers strong {
  color: var(--green-dark);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

#loom-result-message {
  margin: 8px 0 13px;
  font-weight: 800;
}

.loom-section,
.loom-related {
  margin-bottom: 18px;
  padding: 18px 20px;
}

.loom-steps {
  margin: 10px 0 0;
  padding-left: 1.4em;
}

.loom-steps li + li {
  margin-top: 5px;
}

.loom-related__links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.loom-related a {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  font-weight: 800;
  text-decoration: none;
}

.is-playing #loom-intro,
.is-playing #loom-howto,
.is-playing #loom-related {
  display: none;
}

.is-playing .loom-hero {
  margin-bottom: 8px;
  padding-top: 4px;
}

.is-playing h1 {
  font-size: clamp(28px, 3.5vw, 40px);
}

.is-playing .loom-hero__rule {
  margin-top: 4px;
  font-size: 13px;
}

.loom-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.site-footer {
  padding: 24px 16px 28px;
  border-top: 1px solid var(--line);
  background: var(--green-dark);
  color: var(--white);
  text-align: center;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
}

.site-footer a {
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
}

.site-footer p {
  margin: 14px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}

@media (max-width: 1280px) {
  .page-shell {
    grid-template-columns: minmax(0, 1100px);
    width: min(1100px, calc(100% - 32px));
  }

  .ad-rail {
    display: none;
  }
}

@media (max-width: 760px) {
  .header-inner {
    display: block;
    width: min(100% - 24px, 720px);
    padding: 8px 0 6px;
  }

  .site-logo {
    display: inline-block;
    margin-bottom: 4px;
  }

  .site-nav {
    width: 100%;
  }

  .site-nav a {
    padding: 6px 8px;
    font-size: 12px;
  }

  .page-shell {
    width: min(100% - 24px, 720px);
    margin-top: 10px;
  }

  .loom-hero {
    padding-top: 5px;
  }

  h1 {
    font-size: clamp(27px, 8.2vw, 38px);
  }

  .loom-intro {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .loom-intro__action {
    min-width: 0;
    text-align: left;
  }

  .loom-game {
    padding: 13px 12px 15px;
  }

  .loom-game__body {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .loom-frame {
    max-width: 330px;
  }

  .loom-frame__svg {
    max-height: 218px;
  }

  .loom-related__links {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .page-shell {
    width: min(100% - 20px, 390px);
  }

  .loom-hero__rule {
    font-size: 13px;
  }

  .is-playing h1 {
    font-size: 24px;
    line-height: 1.12;
  }

  .is-playing .loom-kicker {
    font-size: 9px;
  }

  .loom-game__header {
    align-items: flex-start;
  }

  .loom-game__header h2 {
    font-size: 20px;
  }

  .loom-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .loom-stage {
    padding: 7px 9px 5px;
  }

  .loom-frame {
    max-width: 250px;
  }

  .loom-frame__svg {
    max-height: 170px;
  }

  .loom-form__row {
    grid-template-columns: minmax(0, 1fr) 74px;
  }

  .loom-form__row .loom-button {
    padding-inline: 10px;
  }

  .loom-result__numbers {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
