:root {
  color-scheme: dark;
  --ink: #f7f0e5;
  --paper: #11100f;
  --muted: #c4b9a9;
  --rule: #4e4130;
  --accent: #edce8b;
  --serif: "Yu Mincho", YuMincho, "Hiragino Mincho ProN", "Noto Serif CJK JP", "MS PMincho", serif;
  font-family: "Yu Gothic", YuGothic, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box }
html { scroll-padding-top: 18px }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 84% 20%, #241f1785, transparent 52%), var(--paper) }
button, input { font: inherit }
button, a { -webkit-tap-highlight-color: transparent }
button { cursor: pointer }
a { color: inherit }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid #f1d292; outline-offset: 4px }
.wrap { width: min(1128px, 89%); margin-inline: auto }
.masthead { border-top: 3px solid #b79961; border-bottom: 1px solid var(--rule) }
.masthead-inner, .brand, nav { display: flex; align-items: center }
.masthead-inner { justify-content: space-between; min-height: 66px }
.brand { gap: .7rem; text-decoration: none; font-family: var(--serif); font-size: 1.35rem; font-weight: 900; letter-spacing: .08em }
.track-mark { display: inline-block; position: relative; transform: skewX(-16deg); width: 39px; height: 23px; border: 3px solid var(--ink); border-radius: 20px }
.track-mark::before { content: ""; position: absolute; inset: 3px; border: 2px solid var(--ink); border-radius: inherit }
.track-mark::after { content: ""; height: 12px; width: 4px; background: var(--accent); position: absolute; right: 9px; top: -5px; border-inline: 2px solid var(--paper) }
nav { gap: 1.7rem; font-size: .875rem; font-weight: 700 }
nav a { text-decoration-thickness: 1px; text-underline-offset: .35em; text-decoration-color: transparent }
nav a:hover { text-decoration-color: currentColor }
.studio { display: grid; grid-template-columns: 1fr 1.04fr; align-items: center; gap: clamp(32px,6vw,90px); padding-block: clamp(38px,4vw,64px) }
.intro { min-width: 0 }
h1, h2, h3, p { margin: 0 }
h1 { font-family: var(--serif); font-weight: 900; font-size: clamp(3.35rem,5.2vw,5.25rem); line-height: 1.22; letter-spacing: -.045em }
h1 em { font-style: normal; color: var(--accent) }
.period { letter-spacing: -.4em }
.lead { color: #d4cabe; font-size: 1rem; line-height: 1.9; margin-top: 1.3rem; text-wrap: pretty }
form { border-top: 1px solid var(--rule); padding-top: 1.5rem; margin-top: 1.9rem }
label { display: inline-block; font-weight: 750; font-size: .95rem; margin-bottom: .6rem }
.entry { display: flex; align-items: stretch; gap: .5rem }
.entry input { width: 0; min-width: 0; flex: 1; height: 52px; border: 1px solid #76674e; border-radius: 4px; background: #211f1b; padding: 0 .9rem; color: var(--ink); font-size: 1.05rem }
.entry input[aria-invalid="true"] { border-color: var(--accent) }
.error { margin-top: .5rem; font-size: .875rem; color: #ffaf93 }
.reading-options { margin-top: .55rem; color: var(--muted); font-size: .875rem }
.reading-options summary { width: fit-content; cursor: pointer; padding: .25rem 0; text-underline-offset: .25em; text-decoration: underline }
.reading-options label { display: block; margin: .4rem 0 .25rem }
.reading-options input { width: min(100%,20rem); border: 1px solid #76674e; border-radius: 4px; background: #211f1b; padding: .6rem .75rem; color: var(--ink); font-size: 1rem }
.interview { margin-top: 1.35rem }
.question-progress { display: flex; align-items: center; gap: .85rem; color: var(--accent); font-size: .82rem; letter-spacing: .08em; font-weight: 700 }
.question-progress::after { content: ""; flex: 1; height: 2px; background: linear-gradient(to right,var(--accent) var(--progress,33.33%),var(--rule) 0) }
.question { border: 0; min-width: 0; padding: 0; margin: .55rem 0 0 }
.question legend { padding: 0; margin-bottom: .75rem; font: 800 clamp(1.05rem,2vw,1.35rem)/1.55 var(--serif) }
.question label { display: flex; align-items: center; gap: .7rem; padding: .65rem .85rem; min-height: 44px; border: 1px solid var(--rule); background: #211e1a; border-radius: 4px; cursor: pointer; margin: 0 0 .45rem; font-weight: 600; line-height: 1.5 }
.question input { accent-color: var(--accent); margin: 0; width: 1rem; height: 1rem; flex-shrink: 0 }
.question label:hover, .question label:has(:checked) { border-color: #b49a67; background: #30291e }
.question label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px }
.question-actions { margin-top: .65rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .55rem }
#next-question { margin-left: auto; padding: .65rem 1.25rem; min-height: 44px; border: 1px solid var(--accent); border-radius: 4px; background: var(--accent); color: #231d14; font-weight: 700 }
#next-question:hover { background: #f3dbab }
#previous-question, .try-again { color: var(--muted); background: none; border: 0; font: inherit; font-size: .9rem; text-decoration: underline; text-underline-offset: .25em; padding: .55rem 0 }
#paddock { display: block; width: 100%; height: auto; border-radius: 5px; border: 1px solid var(--rule) }
.race-card { --metal: #a7aaa1; --metal-dark: #51534d; --plate: #21221f; min-width: 0; border: 1px solid var(--metal-dark); background: #1b1916; border-radius: 5px; overflow: hidden; scroll-margin-block: 12px }
.race-card:focus { outline: none }
.race-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px }
.card-top { background: #24231e; color: #f6e9ce; display: flex; justify-content: space-between; gap: .55rem; align-items: center; min-height: 38px; padding: .45rem 1.2rem; font-size: .875rem; font-weight: 700; letter-spacing: .05em }
.card-label { display: flex; align-items: center; gap: .6rem }
.checks { width: 23px; height: 13px; background: repeating-conic-gradient(#ead5a5 0 25%,transparent 0 50%) 0 0 / 8px 8px; transform: skew(-12deg) }
#card-style { color: #d3c8b6; font-size: .8rem }
#rank-level { color: var(--metal); font: 700 .78rem/1.2 Arial,sans-serif; letter-spacing: .12em; white-space: nowrap }
.illustration { position: relative; background: #cbd2c7; overflow: hidden }
.illustration canvas { display: block; width: 100%; height: auto }
#photo-card { position: absolute; inset: 0; width: 100%; height: 100%; background: transparent; border: 0; cursor: zoom-in }
#photo-card:focus-visible { outline-offset: -4px }
.illustration.zoomed canvas { transform: scale(2.65); transform-origin: var(--cloth-x,47%) var(--cloth-y,34%) }
.photo-tools { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .2rem .65rem; background: #191815; padding: 1px .85rem }
#bib-summary { color: var(--muted); font-size: .78rem }
#zoom-photo { padding: .35rem .15rem; min-height: 34px; border: 0; background: transparent; color: #dbcdb3; font-weight: 700; font-size: .8125rem; text-decoration: underline; text-underline-offset: .25em }
#zoom-photo:hover { color: #fff }
.grade-band { display: flex; align-items: center; justify-content: space-between; gap: .55rem; padding: .45rem 1.45rem; background: var(--plate); border-block: 1px solid var(--metal-dark) }
#grade { font: 800 1.28rem/1.35 var(--serif); color: var(--metal) }
.race-card[data-rank="1"] { --metal: #c2cbd0; --metal-dark: #5a656b; border-top-width: 2px }
.race-card[data-rank="2"] { --metal: #b5ccb6; --metal-dark: #607460; --plate: #232b24 }
.race-card[data-rank="3"] { --metal: #c9c6b3; --metal-dark: #827e67; --plate: #282821; box-shadow: 3px 3px 0 #34332c }
.race-card[data-rank="4"] { --metal: #e3bd8d; --metal-dark: #876947; --plate: #30271f; padding: 3px; box-shadow: 3px 3px 0 #372e25 }
.race-card[data-band="established"] .grade-band { border-bottom: 3px double var(--metal-dark) }
.race-card:is([data-rank="3"],[data-rank="4"]) .identity { margin: .6rem .7rem; padding-block: .45rem; border-left: 2px solid var(--metal-dark) }
.race-card[data-rank="4"] .grade-band { margin-inline: .65rem; border-inline: 1px solid var(--metal-dark) }
.race-card[data-band="graded"] { padding: 4px; border: 3px double var(--metal); box-shadow: 3px 4px 0 var(--metal-dark) }
.race-card[data-rank="5"] { --metal: #edb084; --metal-dark: #79513a; --plate: #36251d }
.race-card[data-rank="6"] { --metal: #dce7f1; --metal-dark: #6e7e8e; --plate: #232c37; padding: 5px }
.race-card[data-rank="7"] { --metal: #ffe0a0; --metal-dark: #9d793b; --plate: #392b17; padding: 6px; box-shadow: 0 0 0 2px #342819, 0 6px 24px #a97b321f }
.race-card[data-band="graded"] .grade-band { justify-content: center; flex-wrap: wrap; padding: .6rem .75rem; background: linear-gradient(105deg,#171614,var(--plate),#171614) }
.race-card[data-band="graded"] .grade-band::before, .race-card[data-band="graded"] .grade-band::after { content: ""; flex: 1; max-width: 75px; height: 3px; border-block: 1px solid var(--metal-dark) }
.race-card[data-band="graded"] #grade { font-size: 1.65rem }
.race-card:is([data-rank="6"],[data-rank="7"]) .identity { text-align: center }
.race-card[data-rank="7"] .identity { margin: .65rem; padding: .75rem; background: linear-gradient(var(--metal-dark),var(--metal-dark)) left top / 1.2rem 1px, linear-gradient(var(--metal-dark),var(--metal-dark)) left top / 1px 1.2rem, linear-gradient(var(--metal-dark),var(--metal-dark)) right bottom / 1.2rem 1px, linear-gradient(var(--metal-dark),var(--metal-dark)) right bottom / 1px 1.2rem; background-repeat: no-repeat }
.race-card[data-rank="7"] .identity h2 { color: #ffe5ab }
.verdict { display: grid; grid-template-columns: clamp(66px,7vw,90px) minmax(0,1fr); align-items: center; gap: .7rem; padding: .9rem 1rem 1rem; border-top: 1px solid var(--metal-dark); background: #201f1b }
.trainer-portrait { overflow: hidden; display: flex; border-radius: 3px; border: 1px solid var(--metal-dark); background: #173d32; aspect-ratio: 1 }
.trainer-portrait img { display: block; width: 100%; height: auto; object-fit: cover }
.dialogue { position: relative; border: 1px solid var(--metal-dark); border-radius: 5px; padding: .65rem .8rem; background: #2b2821 }
.dialogue::before { content: ""; position: absolute; width: 9px; height: 9px; left: -6px; top: 40%; background: #2b2821; border-left: 1px solid var(--metal-dark); border-bottom: 1px solid var(--metal-dark); transform: rotate(45deg) }
.verdict h3 { color: var(--metal); font-size: .8125rem; letter-spacing: .08em }
.verdict p { margin-top: .25rem; font-weight: 650; line-height: 1.65 }
.grade-samples { margin-top: 1rem; color: var(--muted); font-size: .875rem }
.grade-samples summary { width: fit-content; cursor: pointer; text-decoration: underline; text-decoration-color: #756952; text-underline-offset: .25rem; padding: .3rem 0 }
.grade-samples summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px }
#grade-examples { display: grid; gap: .4rem; margin-top: .7rem }
.example-row { display: grid; grid-template-columns: 6.8em repeat(2,minmax(0,1fr)); align-items: stretch; gap: .4rem }
.example-class { align-self: center; color: var(--muted); font-weight: 700 }
#grade-examples button { min-height: 36px; text-align: left; padding: .4rem .6rem; background: #211f1b; border: 1px solid var(--rule); border-radius: 3px; color: var(--ink); font-size: .875rem }
#grade-examples button:hover { background: #3a3021 }
.runner-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; width: 100% }
.runner-grade { flex: none; color: #fff; background: var(--silk); padding: .13rem .4rem; border-radius: 2px; font-size: .75rem; font-weight: 700 }
.identity { padding: 1.05rem 1.45rem 1.1rem; overflow-wrap: anywhere }
.source-name { color: var(--muted); font-size: .875rem; font-weight: 650 }
.identity h2 { font: 900 clamp(1.6rem,3vw,2.55rem)/1.32 var(--serif); letter-spacing: -.035em; margin: .2rem 0 .35rem }
.origin { font-size: 1rem; line-height: 1.65; color: #cfc5b5 }
.comment-box { position: relative; display: flex; gap: .8rem; align-items: flex-start; padding: .9rem 1.45rem 1.1rem; border-top: 1px dashed #574c39; background: #1e201c }
.comment-box h3 { color: #d9cfaa; font-size: .8125rem; letter-spacing: .08em }
.comment-box p { font-family: var(--serif); font-weight: 700; font-size: 1.1rem; line-height: 1.6; margin-top: .15rem }
.mic { display: block; position: relative; flex: none; width: 29px; height: 29px; background: #383a30; border-radius: 50%; margin-top: 1px }
.mic i { position: absolute; width: 7px; height: 11px; border-radius: 5px; background: var(--ink); left: 11px; top: 4px }
.mic::before { content: ""; position: absolute; width: 11px; height: 9px; border: 2px solid var(--ink); border-top: none; border-radius: 0 0 9px 9px; left: 7px; top: 10px }
.mic::after { content: ""; position: absolute; height: 5px; width: 2px; background: var(--ink); top: 19px; left: 14px }
.lineup { border-top: 3px double #776447; padding-block: 1.35rem 3rem }
.lineup-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem }
.lineup-heading h2 { display: flex; align-items: center; gap: .6rem; font-family: var(--serif); font-size: clamp(1.25rem,2.2vw,1.7rem); font-weight: 900 }
.silks { display: inline-block; flex: none; width: 25px; height: 24px; background: linear-gradient(37deg,var(--ink) 35%,#8e7347 35% 46%,var(--ink) 46% 56%,#8e7347 56% 66%,var(--ink) 66%); clip-path: polygon(29% 7%,38% 3%,45% 14%,55% 14%,62% 3%,71% 7%,100% 37%,84% 57%,73% 49%,73% 97%,27% 97%,27% 49%,16% 57%,0% 37%) }
#horse-count { font-weight: 700; font-size: .875rem }
.history-help { margin-top: .4rem; color: var(--muted); font-size: .875rem }
.history-list { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .85rem; margin-top: 1rem }
.runner { position: relative; text-align: left; display: flex; flex-direction: column; gap: .35rem; color: var(--ink); background: #211f1b; border: 1px solid #4a4134; border-top: 3px solid var(--silk); border-radius: 3px; padding: .9rem 1rem; overflow-wrap: anywhere }
.runner:hover { background: #312a20; border-color: #ac9060 }
.runner[aria-pressed="true"] { box-shadow: inset 0 0 0 1px #a48b60 }
.runner-source { color: var(--muted); font-size: .875rem }
.runner-horse { font: 800 1.28rem/1.35 var(--serif) }
.runner-call { font-size: .875rem; line-height: 1.55 }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap }
.try-again { display: block; margin-top: .5rem }
@media (max-width: 800px) {
  .wrap { width: min(92%, 660px) }
  .studio { grid-template-columns: 1fr; gap: 1.65rem; padding-block: 2rem }
  h1 { font-size: clamp(2.7rem,7.9vw,3.7rem) }
  h1 br { display: none }
  .lead { margin-top: .65rem }
  form { margin-top: 1.2rem; padding-top: 1rem }
  .try-again { display: block; text-align: center; font-weight: 700; padding: .4rem; text-underline-offset: .3em }
  .history-list { grid-template-columns: repeat(2,minmax(0,1fr)) }
}
@media (max-width: 480px) {
  .wrap { width: calc(100% - 32px) }
  .masthead-inner { min-height: 56px; flex-wrap: wrap; gap: .3rem .8rem; padding-block: .5rem }
  .brand { font-size: 1.15rem; gap: .45rem }
  .track-mark { width: 30px; height: 19px }
  nav { gap: .8rem; font-size: .825rem }
  .studio { padding-top: 1.5rem }
  h1 { font-size: clamp(2rem,8.2vw,2.55rem); letter-spacing: -.055em }
  .lead { line-height: 1.7 }
  .identity, .comment-box, .verdict { padding-inline: 1rem }
  .history-list { grid-template-columns: 1fr }
  .example-row { grid-template-columns: repeat(2,minmax(0,1fr)); padding-bottom: .45rem; border-bottom: 1px solid var(--rule) }
  .example-class { grid-column: 1 / -1 }
  .verdict { gap: .55rem; grid-template-columns: 60px minmax(0,1fr) }
  .dialogue { padding: .55rem .65rem }
}
@media (prefers-reduced-motion: no-preference) {
  .race-card.reveal .identity, .race-card.reveal .comment-box p { animation: appear .38s ease-out }
  @keyframes appear { from { opacity: .25; transform: translateY(4px) } to { opacity: 1; transform: none } }
}
@media (max-width: 370px) { h1 br { display: block } }

.result-stack { min-width: 0 }
.owner-tools { margin-top: 1rem }
.owner-tools p, .share-note { margin-top: .45rem; color: var(--muted); font-size: .83rem; line-height: 1.55 }
.share-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .55rem 0 }
.owner-tools button, .share-row a, .share-row button, #close-share, .shared-cta { display: inline-block; padding: .6rem .9rem; border: 1px solid #827052; border-radius: 4px; background: #25221c; color: var(--ink); font-size: .9rem; font-weight: 700; text-align: center; text-decoration: none }
.owner-tools button:hover, .share-row a:hover, .share-row button:hover, #close-share:hover { border-color: var(--accent) }
.owner-tools .primary, .share-row .primary, .shared-cta.primary { color: #241b0c; background: var(--accent); border-color: var(--accent) }
#another-idea { color: var(--accent); background: none; border: 0; padding: .3rem 0; text-decoration: underline; text-underline-offset: .25em }
.text-post { display: inline-block; color: var(--accent); padding-block: .6rem; text-underline-offset: .2em; font-size: .88rem }
#share-x:disabled { opacity: .7; cursor: wait }
.shared-view :is(.intro, .lineup, .try-again, .owner-tools, nav a:not(#works-link), .origin) { display: none }
.shared-view .studio { display: block; max-width: 600px; margin: 0 auto }
.shared-cta { display: block; margin-top: 1.2rem }
.viewing-card { overflow: hidden }
#share-dialog { position: fixed; inset: 0; margin: 0; width: 100%; height: 100%; height: 100dvh; max-width: none; max-height: none; padding: 0; background: var(--paper); color: var(--ink); border: 0; overscroll-behavior: contain }
#share-dialog[open] { display: grid; grid-template-rows: auto auto minmax(0,1fr) }
#share-dialog::backdrop { background: #090806cf }
#share-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: max(.65rem,env(safe-area-inset-top)) max(1rem,env(safe-area-inset-right)) .65rem; border-bottom: 1px solid var(--rule) }
#share-title { font-size: 1.1rem; font-family: var(--serif) }
.share-content { max-height: 44dvh; overflow-y: auto; padding: .45rem 1rem .65rem; text-align: center; border-bottom: 1px solid var(--rule) }
.share-content .share-row { justify-content: center }
#share-trouble { max-width: 48rem; margin: .45rem auto 0; font-size: .85rem; color: var(--muted) }
#share-trouble summary { cursor: pointer; text-decoration: underline; text-underline-offset: .2em }
#share-status { line-height: 1.55 }
#share-status:empty { display: none }
.secondary-links a, .secondary-links button { font-size: .82rem }
#copy-field { display: block; width: 100%; margin-top: .6rem }
.viewer-stage { min-height: 0; padding: .6rem .6rem max(.6rem,env(safe-area-inset-bottom)) }
#share-image { display: block; width: 100%; height: 100%; object-fit: contain }
#share-dialog.saving-image .share-content:not(#image-save-tools),
#share-dialog.saving-image.awaiting-jpeg .viewer-stage { display: none }
#save-page-field { width: min(100%,42rem); margin: .5rem auto 0; font-size: 1rem }
#preview-dialog { position: fixed; inset: 0; padding: 0; margin: 0; width: 100%; height: 100%; height: 100dvh; max-width: none; max-height: none; border: 0; color: var(--ink); background: var(--paper) }
#preview-dialog[open] { display: grid; grid-template-rows: auto minmax(0,1fr) }
#preview-dialog header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: max(.6rem,env(safe-area-inset-top)) 1rem .6rem; border-bottom: 1px solid var(--rule) }
#preview-title { font: 700 1.05rem var(--serif) }
#return-result { min-height: 44px; border-radius: 4px; padding: .5rem .8rem; font-weight: 700; border: 1px solid var(--accent); background: var(--accent); color: #241b0c }
#preview-frame { border: 0; width: 100%; height: 100%; display: block }
[hidden] { display: none !important }
