:root {
  --ink: #173c45;
  --ink-soft: #315963;
  --paper: #fff8e8;
  --paper-deep: #f4e5bd;
  --red: #c94b42;
  --red-dark: #91362f;
  --gold: #dcaa3e;
  --green: #467657;
  --teal: #2f7b7c;
  --shadow: 0 18px 50px rgba(42, 37, 23, .18);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #163740; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  background:
    radial-gradient(circle at 15% 5%, rgba(255, 213, 111, .22), transparent 23rem),
    radial-gradient(circle at 90% 90%, rgba(55, 136, 124, .32), transparent 28rem),
    linear-gradient(145deg, #12323a 0%, #20515a 52%, #163941 100%);
  overflow-x: hidden;
  touch-action: manipulation;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 4px solid #ffd46d; outline-offset: 3px; }

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .12;
  background-image: repeating-linear-gradient(105deg, transparent 0 6px, rgba(255,255,255,.13) 7px 8px);
}

.site-header {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff8df;
  position: relative;
  z-index: 2;
}

.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: .05em; }
.brand-mark { width: 38px; height: 38px; border: 2px solid #ffe09a; border-radius: 50% 50% 48% 52%; display: grid; place-items: center; color: #ffe09a; transform: rotate(-8deg); }
.icon-button { border: 1px solid rgba(255,255,255,.45); background: rgba(9,35,41,.52); color: white; border-radius: 999px; padding: 9px 14px; cursor: pointer; }

.game-shell { width: min(1120px, calc(100% - 24px)); margin: 14px auto 26px; position: relative; z-index: 1; }
.screen { animation: screen-in .36s ease-out both; }
.screen[hidden] { display: none !important; }
@keyframes screen-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.start-screen {
  background: var(--paper);
  border: 3px solid #e2c579;
  border-radius: 30px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 58px);
  position: relative;
  overflow: hidden;
}
.start-screen::after { content: ""; position: absolute; width: 260px; height: 260px; border: 48px solid rgba(47,123,124,.07); border-radius: 50%; right: -95px; top: -100px; }
.hero-copy { max-width: 650px; position: relative; z-index: 1; }
.eyebrow, .mini-label { margin: 0 0 8px; color: var(--red-dark); font-size: .83rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 0; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: clamp(2.2rem, 7vw, 5.1rem); line-height: .98; letter-spacing: -.04em; }
h1 span { display: block; color: var(--red); font-size: .55em; letter-spacing: .06em; margin-bottom: 10px; }
.hero-lead { max-width: 610px; font-size: clamp(1rem, 2.2vw, 1.18rem); line-height: 1.9; margin: 24px 0 18px; }
.feature-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 25px; }
.feature-row span { color: var(--ink); background: #f0dca7; border: 1px solid #d4b766; border-radius: 999px; padding: 7px 12px; font-weight: 800; font-size: .88rem; }

.primary-button, .secondary-button { border: 0; border-radius: 14px; font-weight: 900; cursor: pointer; transition: transform .16s ease, filter .16s ease, opacity .16s ease; }
.primary-button { color: white; background: linear-gradient(180deg, #db6154, #af3f37); box-shadow: 0 6px 0 #7d302b, 0 10px 20px rgba(126,48,43,.22); padding: 13px 20px; }
.secondary-button { color: var(--ink); background: #f2e4be; border: 2px solid #d5bb77; padding: 11px 16px; }
.primary-button:hover:not(:disabled), .secondary-button:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.04); }
.primary-button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #7d302b; }
button:disabled { cursor: not-allowed; opacity: .48; }
.big-button { font-size: 1.08rem; padding: 16px 25px; }
.start-note { margin: 14px 0 0; font-size: .84rem; color: #5b6c6e; }

.scroll-preview { position: absolute; right: clamp(25px, 5vw, 70px); top: 45px; width: 260px; transform: rotate(2deg); filter: drop-shadow(0 12px 14px rgba(54,47,26,.19)); }
.scroll-rod { height: 17px; background: linear-gradient(90deg, #694531, #b9854f 15%, #7b4c30 50%, #b9854f 85%, #694531); border-radius: 999px; margin: 0 -16px; position: relative; z-index: 2; }
.chapter-preview { min-height: 91px; padding: 14px 18px; border-inline: 2px solid #d2b36d; display: flex; flex-direction: column; justify-content: center; background: #fff1c9; }
.chapter-preview + .chapter-preview { border-top: 1px dashed #c9a45c; }
.chapter-preview b { color: var(--red-dark); font-size: .72rem; }
.chapter-preview span { font-family: "Yu Mincho", serif; font-weight: 900; font-size: 1.23rem; }
.chapter-preview small { color: #66716a; }
.chapter-preview.jomon { background-image: linear-gradient(110deg, rgba(184,112,63,.13), transparent); }
.chapter-preview.kofun { background-image: linear-gradient(110deg, rgba(61,122,90,.13), transparent); }
.chapter-preview.asuka { background-image: linear-gradient(110deg, rgba(62,90,137,.13), transparent); }

.start-grid { margin-top: 48px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; position: relative; z-index: 1; }
.info-card, .record-card { border: 1px solid #dfca95; border-radius: 18px; background: rgba(255,255,255,.5); padding: 20px; }
.info-card h2, .record-card h2 { margin-top: 0; }
.info-card ol { margin: 0; padding-left: 1.35rem; line-height: 1.75; }
.info-card li + li { margin-top: 7px; }
.record-card { background: var(--ink); color: #fff9e8; }
.record-card .mini-label { color: #ffd776; }
.record-numbers { display: flex; gap: 22px; margin: 14px 0; }
.record-numbers div { display: flex; flex-direction: column; }
.record-numbers strong { font-size: 1.7rem; color: #ffe39a; }
.record-numbers span { font-size: .75rem; opacity: .82; }
.record-card > p:last-child { line-height: 1.7; margin-bottom: 0; font-size: .88rem; }

.game-screen { display: grid; gap: 14px; }
.hud { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; background: rgba(10,35,40,.78); color: white; padding: 12px; border-radius: 18px; backdrop-filter: blur(9px); }
.hud > div { min-width: 0; padding: 5px 10px; border-right: 1px solid rgba(255,255,255,.16); display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.hud > div:last-child { border-right: 0; }
.hud-label { font-size: .72rem; opacity: .75; }
.hud strong { font-size: 1.12rem; white-space: nowrap; }
.timer-box.warning strong { color: #ffbd68; animation: pulse .7s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

.timeline { background: #f4e3b9; border: 2px solid #d0af61; border-radius: 16px; padding: 11px 14px; display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; overflow: hidden; }
.timeline-node { min-width: 0; text-align: center; color: #7d745d; font-size: .68rem; position: relative; padding-top: 18px; }
.timeline-node::before { content: ""; position: absolute; top: 4px; left: 50%; width: 10px; height: 10px; background: #d0ba83; border-radius: 50%; transform: translateX(-50%); box-shadow: 0 0 0 3px #f4e3b9; z-index: 1; }
.timeline-node::after { content: ""; position: absolute; top: 8px; left: -55%; width: 110%; height: 3px; background: #d0ba83; }
.timeline-node:first-child::after { left: 50%; width: 55%; }
.timeline-node.complete { color: var(--ink); font-weight: 900; }
.timeline-node.complete::before { background: var(--red); }
.timeline-node.complete::after { background: var(--red); }
.timeline-node.current::before { width: 15px; height: 15px; top: 1px; background: #ffe078; box-shadow: 0 0 0 3px var(--red); }

.mission-panel { background: var(--paper); border: 3px solid #e0c477; border-radius: 26px; padding: clamp(18px, 4vw, 36px); box-shadow: var(--shadow); }
.mission-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.era-label { margin: 0 0 5px; color: var(--teal); font-size: .8rem; font-weight: 900; letter-spacing: .12em; }
.mission-heading h2 { font-family: "Yu Mincho", serif; font-size: clamp(1.45rem, 4vw, 2.35rem); margin: 0; }
.year-tag { flex: 0 0 auto; border-radius: 999px; background: var(--ink); color: #fff5d7; padding: 8px 12px; font-weight: 800; font-size: .8rem; }
.mission-clue { line-height: 1.75; background: #f3e5bd; border-left: 5px solid var(--gold); padding: 13px 15px; border-radius: 5px 14px 14px 5px; }

.card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 22px 0; }
.history-card { min-height: 165px; border: 2px solid #c7ad6b; background: linear-gradient(155deg, #fffdf6, #f2dfb2); color: var(--ink); border-radius: 18px; padding: 15px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; position: relative; box-shadow: 0 6px 0 #c7ad6b; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.history-card:hover { transform: translateY(-3px) rotate(-.4deg); }
.history-card.selected { border-color: var(--red); background: #ffe2b2; transform: translateY(-6px); box-shadow: 0 8px 0 var(--red-dark), 0 11px 25px rgba(138,49,41,.2); }
.history-card.hinted { animation: hint-glow 1s ease-in-out infinite alternate; }
@keyframes hint-glow { to { box-shadow: 0 6px 0 #c7ad6b, 0 0 0 6px rgba(220,170,62,.38); } }
.history-card.wrong { animation: shake .34s linear; }
@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
.card-number { position: absolute; top: 8px; left: 10px; font-size: .72rem; background: var(--ink); color: white; border-radius: 50%; width: 23px; height: 23px; display: grid; place-items: center; }
.card-symbol { font-size: 2.5rem; line-height: 1; }
.card-name { font-weight: 900; font-size: 1.02rem; }
.card-note { font-size: .73rem; line-height: 1.4; color: #53666a; }

.combine-bar { display: flex; align-items: center; justify-content: space-between; gap: 15px; border-top: 1px dashed #c7ac68; padding-top: 18px; }
.combine-bar p { margin: 0; font-weight: 800; }
.combine-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.feedback-panel { margin-top: 18px; background: #e6f2df; border: 2px solid #75a96f; border-radius: 19px; padding: 18px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px; }
.feedback-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; font-size: 1.7rem; font-weight: 900; }
.feedback-copy h3 { margin: 2px 0 6px; }
.feedback-copy p:last-child { margin: 0; line-height: 1.65; }

.quiz-screen, .upgrade-screen, .result-screen { min-height: 610px; display: grid; place-items: center; }
.quiz-card, .upgrade-card { width: min(790px, 100%); background: var(--paper); border: 3px solid #e0c477; border-radius: 28px; padding: clamp(22px, 5vw, 44px); box-shadow: var(--shadow); }
.quiz-progress { display: flex; justify-content: space-between; gap: 15px; color: var(--ink-soft); }
.quiz-card h2 { font-family: "Yu Mincho", serif; font-size: clamp(1.45rem, 4vw, 2.25rem); line-height: 1.5; }
.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.quiz-choice { border: 2px solid #ceb36e; background: #fffdf6; border-radius: 15px; padding: 15px; color: var(--ink); font-weight: 800; cursor: pointer; text-align: left; }
.quiz-choice:hover { background: #f5e2af; }
.quiz-choice.correct { border-color: var(--green); background: #dff0dc; }
.quiz-choice.incorrect { border-color: var(--red); background: #f7d5cf; }
.quiz-explanation { margin-top: 18px; padding: 17px; border-radius: 15px; background: #e5efdb; line-height: 1.7; }
.quiz-explanation strong { color: var(--red-dark); font-size: 1.12rem; }
.quiz-explanation .primary-button { display: block; margin-left: auto; }

.upgrade-card { text-align: center; }
.upgrade-card h2 { font-family: "Yu Mincho", serif; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.upgrade-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 25px; }
.upgrade-option { border: 2px solid #ceb36e; border-radius: 18px; background: #fffaf0; padding: 20px 12px; cursor: pointer; color: var(--ink); }
.upgrade-option:hover { background: #f3dfab; transform: translateY(-3px); }
.upgrade-option span { display: block; font-size: 2.3rem; }
.upgrade-option strong { display: block; margin: 7px 0; }
.upgrade-option small { line-height: 1.5; display: block; }

.result-screen { display: block; }
.result-banner { position: relative; text-align: center; background: var(--paper); border: 3px solid #e0c477; border-radius: 28px 28px 15px 15px; padding: 34px 20px; overflow: hidden; }
.result-banner::before, .result-banner::after { content: ""; position: absolute; width: 180px; height: 180px; border: 35px solid rgba(201,75,66,.07); border-radius: 50%; }
.result-banner::before { left: -85px; top: -80px; }.result-banner::after { right: -85px; bottom: -90px; }
.result-banner h2 { margin: 4px 0 10px; font-family: "Yu Mincho", serif; font-size: clamp(2rem, 5vw, 3.4rem); }
.result-score { display: flex; justify-content: center; align-items: baseline; gap: 7px; margin-top: 18px; }
.result-score strong { color: var(--red); font-size: clamp(2.8rem, 8vw, 5.2rem); line-height: 1; }
.rank-medal { position: absolute; right: clamp(22px, 7vw, 80px); top: 32px; width: 78px; height: 78px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: #ffe295; border: 5px double #ffe295; font: 900 2.4rem/1 serif; transform: rotate(8deg); }
.result-grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 14px; margin-top: 14px; }
.result-stats, .scroll-review, .ranking-panel { background: var(--paper); border: 2px solid #d9bd74; border-radius: 18px; padding: 20px; }
.result-stats h3, .scroll-review h3 { margin-top: 0; }
.result-stats dl { margin: 0; }
.result-stats dl div { display: flex; justify-content: space-between; border-bottom: 1px dashed #d6bd80; padding: 9px 0; }
.result-stats dd { font-weight: 900; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.scroll-review ol { margin: 0; padding-left: 1.3rem; max-height: 310px; overflow: auto; }
.scroll-review li { padding: 7px 4px; line-height: 1.5; }
.ranking-panel { margin-top: 14px; }
.ranking-panel .itc-ranking__tabs button { background: #f0dfb3; }

.game-footer { width: min(1000px, calc(100% - 30px)); margin: 0 auto; color: rgba(255,255,255,.72); text-align: center; font-size: .78rem; padding: 0 0 max(22px, env(safe-area-inset-bottom)); }

@media (max-width: 900px) {
  .scroll-preview { position: relative; right: auto; top: auto; width: min(100%, 620px); transform: none; margin: 35px auto 0; display: grid; grid-template-columns: repeat(3, 1fr); }
  .scroll-rod { display: none; }
  .chapter-preview { min-height: 120px; border: 1px solid #d2b36d; }
  .start-grid { margin-top: 25px; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .result-grid { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
  .game-shell { width: min(100% - 14px, 1120px); margin-top: 7px; }
  .site-header { width: calc(100% - 20px); padding-top: 10px; }
  .brand { font-size: .88rem; }.brand-mark { width: 32px; height: 32px; }
  .icon-button { padding: 7px 10px; font-size: .79rem; }
  .start-screen { border-radius: 22px; padding: 22px 17px; }
  .hero-lead { line-height: 1.72; }
  .scroll-preview { grid-template-columns: 1fr; }
  .chapter-preview { min-height: 82px; }
  .start-grid { grid-template-columns: 1fr; }
  .hud { grid-template-columns: repeat(4, 1fr); padding: 7px; position: sticky; top: 4px; z-index: 8; }
  .hud > div { padding: 3px 4px; flex-direction: column; align-items: center; gap: 0; border-right: 0; }
  .hud > div:first-child { display: none; }
  .hud strong { font-size: .92rem; }
  .timeline { padding-inline: 8px; }
  .timeline-node span { display: none; }
  .timeline-node { height: 15px; padding: 0; }
  .mission-panel { border-radius: 20px; padding: 17px 12px; }
  .mission-heading { display: block; }
  .year-tag { display: inline-block; margin-top: 9px; }
  .mission-clue { margin-bottom: 15px; }
  .card-grid { gap: 9px; margin: 15px 0; }
  .history-card { min-height: 137px; padding: 12px 7px; }
  .card-symbol { font-size: 2rem; }.card-name { font-size: .9rem; }.card-note { font-size: .68rem; }
  .combine-bar { display: block; }
  .combine-bar p { margin-bottom: 12px; text-align: center; }
  .combine-actions { display: grid; grid-template-columns: 1fr 1fr; }
  #combineButton { grid-column: 1 / -1; }
  .feedback-panel { grid-template-columns: auto 1fr; }
  .feedback-panel .primary-button { grid-column: 1 / -1; }
  .quiz-screen, .upgrade-screen { min-height: 520px; }
  .quiz-card, .upgrade-card { border-radius: 20px; padding: 22px 16px; }
  .quiz-choices { grid-template-columns: 1fr; }
  .upgrade-grid { grid-template-columns: 1fr; }
  .upgrade-option { display: grid; grid-template-columns: auto 1fr; text-align: left; column-gap: 13px; align-items: center; padding: 13px; }
  .upgrade-option span { grid-row: 1 / span 2; }.upgrade-option strong { margin: 0; }.upgrade-option small { grid-column: 2; }
  .rank-medal { position: static; margin: 15px auto 0; }
  .result-actions { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
