:root {
  --ink: #2a1d12;
  --ink-soft: #5a4632;
  --paper: rgba(246, 237, 216, .93);
  --paper-edge: #b79a64;
  --accent: #8a2a1c;
  --c-iamb: #1f6f78;
  --c-trochee: #a02a2a;
  --c-anapaest: #a8741a;
  --c-dactyl: #5d3a8a;
  --c-spondee: #3a7a34;
  --c-free: #6b5b45;
  --serif: "IM Fell English", "Palatino Linotype", Georgia, serif;
  --sc: "IM Fell English SC", var(--serif);
}
html[lang="ja"] {
  --serif: "IM Fell English", "Zen Antique", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --sc: "IM Fell English SC", "Zen Antique", "Yu Mincho", "Hiragino Mincho ProN", serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 6.5rem; }
body {
  margin: 0; font-family: var(--serif); color: var(--ink);
  background: #1b1410; font-size: 1.15rem; line-height: 1.6;
}
a { color: var(--accent); }

#bg { position: fixed; inset: 0; z-index: -2; }
.bg-layer {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  opacity: 0; transition: opacity 1.4s ease;
}
.bg-layer.on { opacity: 1; }
#veil { position: fixed; inset: 0; z-index: -1;
  background: radial-gradient(ellipse at center, rgba(20,12,6,.15), rgba(20,12,6,.55)); }

.topnav {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 1rem; flex-wrap: wrap;
  justify-content: space-between; align-items: baseline;
  padding: .55rem 1.2rem; background: rgba(27,20,16,.88); backdrop-filter: blur(4px);
  color: #f1e6c8;
}
.topnav a { color: #f1e6c8; text-decoration: none; }
.brand { font-family: var(--sc); font-size: 1.3rem; letter-spacing: .05em; }
.topnav nav { display: flex; gap: 1.1rem; font-size: 1rem; }
.topnav nav a:hover { text-decoration: underline; }
.topnav nav .lang { border: 1px solid rgba(241,230,200,.5); padding: 0 .6rem; border-radius: 99px; }

.toolbar {
  position: sticky; top: var(--nav-h, 3.1rem); z-index: 19; display: flex; flex-wrap: wrap; gap: .3rem 1.1rem;
  align-items: center; padding: .7rem 1.2rem; font-size: .95rem;
  background: rgba(60,44,28,.9); color: #f1e6c8;
}
.toolbar label { cursor: pointer; white-space: nowrap; }
.tb-title { font-family: var(--sc); }
.tb-hint { margin-left: auto; opacity: .75; font-style: italic; }

main { padding-bottom: 3rem; }
section { min-height: 60vh; display: flex; align-items: center; justify-content: center; padding: 3rem 1rem; }
.hero { min-height: 80vh; }
.panel {
  width: min(780px, 100%); background: var(--paper); border: 1px solid var(--paper-edge);
  border-radius: 6px; padding: 1.8rem clamp(1rem, 4vw, 2.6rem);
  box-shadow: 0 10px 40px rgba(0,0,0,.45), inset 0 0 60px rgba(150,110,50,.18);
}
.hero-panel { text-align: center; }
h1 { font-family: var(--sc); font-weight: 400; font-size: clamp(2.6rem, 8vw, 4.4rem); margin: .1em 0; letter-spacing: .04em; color: var(--accent); }
h2 { font-family: var(--sc); font-weight: 400; font-size: 1.9rem; margin: 0 0 .6rem; color: var(--accent); }
h3 { font-family: var(--sc); font-weight: 400; font-size: 1.3rem; margin: 1.4rem 0 .3rem; }
h4 { margin: 0; font-size: 1.1rem; }
.kicker { font-style: italic; margin: 0; color: var(--ink-soft); }
.lead { font-size: 1.3rem; font-style: italic; }
.small { font-size: .95rem; color: var(--ink-soft); }
.small-panel { font-size: 1rem; }
.btn {
  display: inline-block; margin-top: .6rem; padding: .45rem 1.4rem; border: 1px solid var(--accent);
  color: var(--accent); background: transparent; font: inherit; font-family: var(--sc);
  text-decoration: none; border-radius: 3px; cursor: pointer;
}
.btn:hover, .btn:focus-visible { background: var(--accent); color: #f6edd8; }
.btn.sm { margin: 0; padding: .15rem .8rem; font-size: .95rem; }
.s-demo { font-weight: bold; color: var(--accent); }
.w-demo { color: var(--ink-soft); font-style: italic; }
.bar-demo { color: var(--accent); font-weight: bold; }

.feet-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .7rem; margin: 1rem 0 .4rem; }
.fcard {
  font: inherit; text-align: left; cursor: pointer; padding: .7rem .8rem; border: 2px solid var(--fc);
  background: rgba(255,255,255,.35); border-radius: 5px; color: var(--ink);
}
.fcard:hover, .fcard:focus-visible, .fcard.playing { background: var(--fc); color: #fff8e8; }
.fcard .fname { font-family: var(--sc); font-size: 1.15rem; }
.fcard .fsound { font-size: 1.35rem; font-style: italic; }
.fcard .fsound b { font-style: normal; }
.fcard .fdesc { font-size: .9rem; opacity: .85; }

.measure-list { list-style: none; padding: 0; margin: .6rem 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.measure-list li { border: 1px solid var(--paper-edge); padding: .25rem .8rem; border-radius: 99px; background: rgba(255,255,255,.35); }
.measure-list span { color: var(--ink-soft); margin-left: .4rem; font-style: italic; }
.builder { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem 1rem; align-items: end; margin: .8rem 0; }
.builder label { display: flex; flex-direction: column; font-size: .95rem; }
.builder .check { flex-direction: row; gap: .4rem; align-items: center; }
select { font: inherit; padding: .25rem .4rem; background: #fbf4e0; color: var(--ink); border: 1px solid var(--paper-edge); border-radius: 3px; }
.b-out { grid-column: 1 / -1; padding: .8rem 1rem; border-left: 4px solid var(--accent); background: rgba(255,255,255,.35); }
.b-name { font-family: var(--sc); font-size: 1.5rem; color: var(--accent); }
.b-pattern { font-size: 1.25rem; letter-spacing: .03em; margin: .2rem 0; word-spacing: .1em; }
.b-pattern b { color: var(--accent); }
.b-info { font-size: .95rem; color: var(--ink-soft); }

.rules { list-style: none; counter-reset: r; padding: 0; margin: 1rem 0 0; display: grid; gap: .9rem; }
.rules li { counter-increment: r; padding-left: 2.6rem; position: relative; }
.rules li::before { content: counter(r); position: absolute; left: 0; top: 0; width: 1.9rem; height: 1.9rem; border: 1px solid var(--accent); border-radius: 50%; text-align: center; line-height: 1.8rem; color: var(--accent); }
.rules p { margin: .1rem 0 0; }

.poem { min-height: 50vh; }
.poem .panel { text-align: center; }
.poem-head { font-size: .95rem; color: var(--ink-soft); font-style: italic; margin-bottom: .4rem; }
.poem-title { font-family: var(--sc); font-size: 1.6rem; margin: 0; color: var(--accent); }
.poem-intro { text-align: left; margin: .6rem 0 1.2rem; font-size: 1.05rem; }
.verse { margin: 1.6rem 0; padding-top: 1.1rem; border-top: 1px dotted var(--paper-edge); }
.verse:first-of-type { border-top: 0; }
.line {
  font-size: clamp(1.35rem, 4.4vw, 2.1rem); line-height: 1.5; padding: .2rem .3rem; border-radius: 4px;
  font-style: italic; cursor: help; transition: background .2s;
}
.line:hover { background: rgba(138,42,28,.07); }
.syl { position: relative; display: inline-block; padding: 0 .02em; transition: color .15s, background .15s; outline-offset: 2px; }
.syl.wend { margin-right: .28em; }
.foot { display: inline-block; position: relative; padding: 0 .08em; border-bottom: 3px solid transparent; border-radius: 3px; vertical-align: top; }
.bar { display: none; color: var(--accent); font-style: normal; font-weight: bold; padding: 0 .08em; }
.flabel { display: none; position: absolute; left: 0; right: 0; bottom: -1.2em; font-size: .5em; font-style: normal; font-family: var(--sc); text-align: center; white-space: nowrap; color: var(--fc); }
.foot { --fc: var(--c-free); }
.t-iamb { --fc: var(--c-iamb); } .t-trochee { --fc: var(--c-trochee); } .t-anapaest { --fc: var(--c-anapaest); }
.t-dactyl { --fc: var(--c-dactyl); } .t-spondee { --fc: var(--c-spondee); }

.show-feet .foot { border-bottom-color: var(--fc); background: color-mix(in srgb, var(--fc) 9%, transparent); }
.show-feet .bar { display: inline; }
.show-names .flabel { display: block; }
.show-names .line { padding-bottom: 1.1rem; }
.show-marks .line { padding-top: 1.3rem; }
.show-marks .syl::before {
  content: attr(data-mark); position: absolute; left: 0; right: 0; top: -1.15em; text-align: center;
  font-size: .42em; font-style: normal; font-family: var(--sc); color: var(--ink-soft); letter-spacing: .04em;
}
.show-marks .syl.S { font-weight: bold; color: var(--accent); }
.show-marks .syl.S::before { color: var(--accent); }
.syl:hover, .syl:focus-visible { background: rgba(138,42,28,.15); }
.syl.playing { background: var(--accent); color: #fff8e8 !important; border-radius: 3px; }

.vmeta { display: flex; flex-wrap: wrap; gap: .5rem .8rem; justify-content: center; align-items: center; margin-top: .6rem; }
.vname { font-family: var(--sc); font-size: 1.1rem; color: var(--ink); border: 1px solid var(--paper-edge); background: rgba(255,255,255,.4); padding: .05rem .8rem; border-radius: 99px; cursor: help; }
.vname i { color: var(--ink-soft); font-style: italic; font-family: var(--serif); margin-left: .4rem; font-size: .95rem; }
body:not(.show-verse) .vname { display: none; }
.vnote { margin: .6rem auto 0; max-width: 40em; text-align: left; font-size: 1rem; color: var(--ink-soft); }

.verse.quiz .syl::before, .verse.quiz .flabel { display: none !important; }
.verse.quiz .bar { display: none !important; }
.verse.quiz .foot { border-bottom-color: transparent !important; background: none !important; }
.verse.quiz .syl.S { font-weight: normal; color: inherit; }
.verse.quiz .syl { cursor: pointer; border-bottom: 1px dashed var(--paper-edge); }
.verse.quiz .vname { display: none; }
.verse.quiz .syl.guess { background: rgba(138,42,28,.28); font-weight: bold; }
.verse.quiz .syl.right { background: rgba(58,122,52,.35); }
.verse.quiz .syl.wrong { background: rgba(160,42,42,.35); text-decoration: line-through; }
.verse.quiz .syl.missed { background: rgba(168,116,26,.4); }
.quizbox { display: none; margin: .8rem auto 0; padding: .8rem; max-width: 34em; border: 1px dashed var(--accent); border-radius: 5px; text-align: left; font-size: 1rem; }
.verse.quiz .quizbox { display: block; }
.quizbox .row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: .4rem 0; }
.qfeed { font-style: italic; min-height: 1.4em; }
.qfeed .ok { color: var(--c-spondee); } .qfeed .no { color: var(--c-trochee); }

.verse.free .syl.S { font-weight: bold; color: var(--c-free); }
.verse.free .syl.S::before { color: var(--c-free); }

.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin: 1rem 0; text-align: center; }
.compare .verse { margin: 0; padding: .6rem; border: 1px solid var(--paper-edge); border-radius: 5px; background: rgba(255,255,255,.3); }
.compare .line { font-size: 1.5rem; }
.compare .poem-head { margin: 0; }

#tip {
  position: fixed; z-index: 50; max-width: 18rem; padding: .55rem .8rem; background: #1b1410; color: #f6edd8;
  font-size: .95rem; line-height: 1.35; border-radius: 5px; border: 1px solid var(--tc, #b79a64); pointer-events: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
#tip b { font-family: var(--sc); font-weight: 400; font-size: 1.1rem; color: #f3c98a; }
#tip .dim { opacity: .75; font-size: .88rem; }

@media (max-width: 640px) {
  .tb-hint { display: none; }
  .toolbar { top: var(--nav-h, 3.9rem); }
  .topnav nav { gap: .7rem; font-size: .95rem; }
  body { font-size: 1.05rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; } .bg-layer { transition: none; }
}

/* Checkboxes and speed slider, in the theme colours */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; margin: 0 .35em 0 0; width: 1.05em; height: 1.05em;
  border: 1.5px solid var(--accent); border-radius: 2px; background: rgba(255, 255, 255, .45);
  vertical-align: -.15em; cursor: pointer; display: inline-grid; place-content: center;
}
input[type="checkbox"]::after {
  content: ""; width: .55em; height: .3em; border-left: 2px solid #f6edd8; border-bottom: 2px solid #f6edd8;
  transform: rotate(-45deg) translate(.03em, -.05em); opacity: 0;
}
input[type="checkbox"]:checked { background: var(--accent); }
input[type="checkbox"]:checked::after { opacity: 1; }
input[type="checkbox"]:focus-visible, input[type="range"]:focus-visible { outline: 2px solid var(--paper-edge); outline-offset: 2px; }

.tempo { display: inline-flex; align-items: center; gap: .5em; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 7.5rem; height: 1.2rem; background: transparent; cursor: pointer; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--paper-edge); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 3px; background: var(--paper-edge); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 1rem; height: 1rem; margin-top: -6.5px; border-radius: 50%; background: var(--accent); border: 2px solid #f6edd8; box-shadow: 0 0 0 1px var(--accent); }
input[type="range"]::-moz-range-thumb { width: .8rem; height: .8rem; border-radius: 50%; background: var(--accent); border: 2px solid #f6edd8; box-shadow: 0 0 0 1px var(--accent); }

/* The toolbar is dark, so the controls there use the paper and gold tones */
.toolbar input[type="checkbox"] { border-color: #d9c08a; background: transparent; }
.toolbar input[type="checkbox"]:checked { background: #d9c08a; }
.toolbar input[type="checkbox"]::after { border-color: #3c2c1c; }
.toolbar input[type="range"]::-webkit-slider-runnable-track { background: rgba(217, 192, 138, .5); }
.toolbar input[type="range"]::-moz-range-track { background: rgba(217, 192, 138, .5); }
.toolbar input[type="range"]::-webkit-slider-thumb { background: #d9c08a; border-color: #3c2c1c; box-shadow: 0 0 0 1px #d9c08a; }
.toolbar input[type="range"]::-moz-range-thumb { background: #d9c08a; border-color: #3c2c1c; box-shadow: 0 0 0 1px #d9c08a; }
.toolbar input:focus-visible { outline-color: #f1e6c8; }

/* Align checkboxes with their label text */
.toolbar label { display: inline-flex; align-items: center; line-height: 1.2; }
input[type="checkbox"] { vertical-align: middle; flex: none; position: relative; top: 0; }
