/*
 * Hi!story まなび の共通の見た目。
 * 方向性: 「昔の日本だな」と分かる、親しみやすい戦国。陣幕の紺・和紙の生成り・朱・金。
 * フォントは端末にあるものだけ（学校のフィルター・外部への通信を避ける）。本文は UD フォントを優先。
 */
:root {
  color-scheme: light;
  --navy: #1f2f4a;
  --navy-2: #2d4470;
  --paper: #f3ead6;
  --paper-hi: #fffaf0;
  --ink: #23262b;
  --ink-soft: #5b5a55;
  --accent: #c8452b;
  --accent-deep: #9d3019;
  --gold: #c39a3e;
  --gold-hi: #e9c46a;
  --line: #d9ccb0;
  --mincho:
    'Hiragino Mincho ProN', 'Yu Mincho', 'YuMincho', 'Noto Serif JP', serif;
  --gothic:
    'BIZ UDPGothic', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic',
    'Noto Sans JP', sans-serif;
  --radius: 12px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--navy);
  color: var(--ink);
  font-family: var(--gothic);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button,
input {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled {
  cursor: default;
}
[hidden] {
  display: none !important;
}
:focus-visible {
  outline: 3px solid var(--gold-hi);
  outline-offset: 3px;
}

/* ---------- ボタン ---------- */
.btn-main,
.btn-sub {
  min-height: 52px;
  padding: 10px 22px;
  border-radius: 12px;
  font-weight: bold;
  font-size: 18px;
  letter-spacing: 1px;
}
.btn-main {
  border: 0;
  background: linear-gradient(#d4553a, var(--accent-deep));
  color: var(--paper-hi);
  box-shadow:
    0 4px 0 #6e200f,
    inset 0 1px 0 #ffffff40;
}
.btn-main:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #6e200f;
}
.btn-sub {
  border: 2px solid var(--navy);
  background: var(--paper-hi);
  color: var(--navy);
}

/* ---------- タイトル（1画面） ---------- */
/* タイトルの文字だけに使う書体（使う文字だけを切り出して同梱。外部から読み込まない。SIL OFL: public/fonts/OFL-*.txt） */
@font-face {
  font-family: 'Kaisei Tokumin Title';
  src: url('/fonts/kaisei-tokumin-title.woff2') format('woff2');
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: 'Yuji Boku Title';
  src: url('/fonts/yuji-boku-title.woff2') format('woff2');
  font-display: swap;
}
.title {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  background:
    url('/img/title.webp') right center / cover no-repeat,
    #f4c99a;
}
.title::before {
  /* 左を明るくして、文字を読みやすく */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    #fff6e8f5 0%,
    #fff6e8d9 42%,
    #fff6e833 75%,
    #fff6e800 100%
  );
}
.title-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: clamp(6px, 1.8vh, 20px);
  padding: max(14px, env(safe-area-inset-top)) clamp(16px, 4vw, 56px)
    max(12px, env(safe-area-inset-bottom));
}
.service-logo {
  display: block;
  height: clamp(44px, 8vh, 72px);
  width: auto;
}
.title-logo {
  align-self: center;
}
.title-kicker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-weight: bold;
  letter-spacing: 5px;
  color: var(--navy);
  font-size: clamp(14px, 2vh, 18px);
}
.title-kicker::before {
  content: '';
  width: 28px;
  height: 2px;
  background: var(--accent);
}
/* 「ハイスト」の朱色の札 */
.haisuto {
  display: inline-block;
  padding: 4px 10px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--paper-hi);
  font:
    400 clamp(18px, 2.6vh, 24px) / 1 'Yuji Boku Title',
    var(--mincho);
  letter-spacing: 3px;
  box-shadow:
    0 2px 0 var(--accent-deep),
    inset 0 0 0 2px #ffffff40;
  transform: rotate(-3deg);
}
.title-logo h1 {
  margin: 0.15em 0 0.1em;
  line-height: 1;
  color: var(--navy);
}
.t-allstar {
  display: block;
  white-space: nowrap;
  font:
    800 clamp(36px, min(6.4vw, 10vh), 92px) / 1.1 'Kaisei Tokumin Title',
    var(--mincho);
  letter-spacing: -0.02em;
  /* 金の縁取りと影で、少し立体に */
  text-shadow:
    0 2px 0 #fffaf0,
    0 -1px 0 #fffaf0,
    0 5px 0 #c39a3e66,
    0 10px 18px #1f2f4a40;
}
.t-kassen {
  display: block;
  width: fit-content;
  margin-top: 0.02em;
  font:
    400 clamp(76px, min(15vw, 19vh), 184px) / 1 'Yuji Boku Title',
    var(--mincho);
  color: var(--accent);
  letter-spacing: 0.04em;
  text-shadow:
    3px 3px 0 #fffaf0,
    6px 7px 0 #6e200f,
    0 14px 26px #6e200f55;
  transform: rotate(-2deg);
  transform-origin: left center;
}
.title-lead {
  margin: 0;
  font-size: clamp(14px, 2vh, 18px);
  line-height: 1.75;
  font-weight: bold;
  color: var(--ink);
}
.title-menu {
  display: grid;
  gap: 10px;
}
.menu-main {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 22px 8px 8px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(#d4553a, var(--accent-deep));
  color: var(--paper-hi);
  text-align: left;
  box-shadow:
    0 5px 0 #6e200f,
    0 12px 24px #6e200f40;
  animation: invite 2.4s ease-in-out infinite;
}
.menu-main:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #6e200f;
}
@keyframes invite {
  50% {
    transform: translateY(-2px);
  }
}
.menu-face {
  width: clamp(44px, 6.5vh, 60px);
  height: clamp(44px, 6.5vh, 60px);
  border-radius: 50%;
  border: 3px solid var(--paper-hi);
  flex-shrink: 0;
}
.menu-text {
  display: grid;
  gap: 2px;
}
.menu-text b {
  font-size: clamp(18px, 2.7vh, 23px);
  letter-spacing: 1px;
}
.menu-text small {
  font-size: 14px;
  opacity: 0.9;
}
.menu-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.menu-sub {
  display: grid;
  gap: 2px;
  justify-items: start;
  padding: 10px 12px;
  min-height: 60px;
  border: 2px solid var(--navy);
  border-radius: 14px;
  background: #fffaf0f0;
  color: var(--navy);
  text-align: left;
  box-shadow: 0 4px 0 var(--navy);
}
.menu-sub:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--navy);
}
.menu-sub b {
  font-size: clamp(14px, 1.5vw, 16px);
  white-space: nowrap;
}
.menu-sub small {
  font-size: 13px;
  color: var(--ink-soft);
}
.title-note {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* 箱とカード */
.showcase {
  position: relative;
  z-index: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}
.mockup {
  position: relative;
  z-index: 2;
  width: min(92%, 64vh);
  height: auto;
  filter: drop-shadow(0 24px 30px #3b1a0a66);
  animation: rise 0.9s cubic-bezier(0.2, 0.8, 0.2, 1.1) both;
}
.showcase-cards {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.showcase-cards img {
  position: absolute;
  width: clamp(80px, min(13vw, 20vh), 170px);
  aspect-ratio: 63 / 88;
  border-radius: 6%;
  box-shadow:
    0 0 0 3px #fffaf0,
    0 16px 26px #3b1a0a66;
  animation: deal 0.8s cubic-bezier(0.2, 0.8, 0.2, 1.1) both;
}
.showcase-cards img:nth-child(1) {
  left: 2%;
  top: 14%;
  --r: -14deg;
  animation-delay: 0.35s;
}
.showcase-cards img:nth-child(2) {
  right: 0;
  top: 8%;
  --r: 12deg;
  animation-delay: 0.5s;
}
.showcase-cards img:nth-child(3) {
  right: 4%;
  bottom: 8%;
  --r: 8deg;
  z-index: 3;
  animation-delay: 0.65s;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.94);
  }
}
@keyframes deal {
  from {
    opacity: 0;
    transform: translateY(-30px) rotate(0deg) scale(0.8);
  }
  to {
    opacity: 1;
    transform: rotate(var(--r));
  }
}

/* モードを選んだ後の設定パネル */
.setup-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #1f2f4a99;
  z-index: 10;
}
.panel-card {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 24px;
  border-radius: 18px;
  background: var(--paper-hi);
  box-shadow: 0 24px 60px #0b1424a0;
  display: grid;
  gap: 10px;
}
.panel-card h2 {
  margin: 0 0 4px;
  font: 800 26px var(--mincho);
  color: var(--navy);
}
.panel-label {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: bold;
  color: var(--ink-soft);
}
.panel-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  color: var(--ink-soft);
}
.deck-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.deck-tile {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: white;
  cursor: pointer;
  text-align: center;
}
.deck-tile input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.deck-tile:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #c8452b33;
}
.deck-tile:has(input:focus-visible) {
  outline: 3px solid var(--gold-hi);
}
.deck-faces {
  display: flex;
}
.deck-faces img {
  width: 58px;
  aspect-ratio: 63 / 88;
  object-fit: cover;
  border-radius: 5px;
  box-shadow: 0 3px 8px #0003;
}
.deck-faces img + img {
  margin-left: -18px;
  transform: rotate(6deg) translateY(3px);
}
.deck-tile strong {
  font: 800 19px var(--mincho);
  color: var(--navy);
}
.deck-tile span {
  font-size: 13px;
  color: var(--ink-soft);
}
.levels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 2px solid var(--navy);
  border-radius: 10px;
  overflow: hidden;
}
.levels label {
  position: relative;
}
.levels input {
  position: absolute;
  opacity: 0;
}
.levels span {
  display: grid;
  place-items: center;
  min-height: 46px;
  font-weight: bold;
  cursor: pointer;
  color: var(--navy);
}
.levels label + label span {
  border-left: 2px solid var(--navy);
}
.levels input:checked + span {
  background: var(--navy);
  color: var(--paper-hi);
}
.levels input:focus-visible + span {
  outline: 3px solid var(--gold-hi);
  outline-offset: -5px;
}
.join-row {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-top: 1.5px dashed var(--line);
  border-bottom: 1.5px dashed var(--line);
}
.join-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 8px;
}
#room-code {
  min-height: 52px;
  font: bold 26px var(--gothic);
  letter-spacing: 10px;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: white;
}
#room-code:focus {
  border-color: var(--navy);
  outline: none;
}
.panel-or {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}
.setup-error {
  margin: 0;
  color: var(--accent-deep);
  font-weight: bold;
}

/* ---------- ダイアログ ---------- */
dialog {
  border: 0;
  border-radius: 18px;
  padding: 28px;
  background: var(--paper-hi);
  color: var(--ink);
  box-shadow: 0 24px 60px #0b1424a0;
  max-width: min(520px, 92vw);
  width: 92vw;
  text-align: center;
}
dialog::backdrop {
  background: #0b1424b0;
}
dialog h2 {
  margin: 0 0 8px;
  font: 800 26px var(--mincho);
  color: var(--navy);
}
dialog p {
  font-size: 16px;
  line-height: 1.8;
}
dialog .btn-main,
dialog .btn-sub {
  width: 100%;
  margin-top: 6px;
}
.dialog-label {
  margin: 0;
  font-weight: bold;
  letter-spacing: 4px;
  color: var(--accent);
}
.room-code {
  margin: 4px 0;
  padding-left: 18px;
  font: 800 72px var(--gothic);
  letter-spacing: 18px;
  color: var(--navy);
}
.waiting-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.waiting-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite;
}
.waiting-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.waiting-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}
.detail-meta {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}
.detail-meta span {
  font-size: 14px;
  font-weight: bold;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--paper);
}
.detail-effect {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--paper);
}
.detail-effect h3 {
  margin: 0 0 4px;
  font-size: 16px;
  color: var(--navy);
}
.detail-effect p {
  margin: 0;
  font-size: 16px;
  line-height: 1.75;
}
.mark {
  display: inline-grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  margin-right: 6px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  font-size: 0.85em;
}
.log-dialog {
  position: relative;
  text-align: left;
  max-height: 80dvh;
}
#logs {
  margin: 0;
  padding-left: 1.6em;
  max-height: 60dvh;
  overflow: auto;
  line-height: 1.8;
}
#logs li {
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
}
.result h2 {
  font-size: 40px;
}
.result-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.error {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 40;
  margin: 0;
  max-width: 90vw;
  padding: 12px 18px;
  border-radius: 12px;
  background: #fff3ee;
  border-left: 6px solid var(--accent);
  color: var(--accent-deep);
  font-weight: bold;
  box-shadow: 0 8px 24px #0003;
}
.error:empty {
  display: none;
}

/* ---------- 縦向き・狭い画面: 上に箱とカード、下に文字とメニュー ---------- */
@media (max-aspect-ratio: 1/1) {
  .title {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    background-position: 75% center;
  }
  .title::before {
    background: linear-gradient(
      180deg,
      #fff6e800 0%,
      #fff6e8cc 40%,
      #fff6e8f5 60%
    );
  }
  .showcase {
    grid-row: 1;
    overflow: hidden;
    padding: calc(clamp(44px, 8vh, 72px) + 20px) 0 8px;
  }
  .mockup {
    width: auto;
    height: 100%;
    max-height: 40vh;
    max-width: 78%;
    object-fit: contain;
  }
  .showcase-cards {
    top: calc(clamp(44px, 8vh, 72px) + 20px);
  }
  .showcase-cards img {
    width: clamp(64px, min(16vw, 13vh), 130px);
  }
  .showcase-cards img:nth-child(1) {
    left: 3%;
    top: 4%;
  }
  .showcase-cards img:nth-child(2) {
    right: 3%;
    top: 0;
  }
  .showcase-cards img:nth-child(3) {
    right: 6%;
    bottom: 4%;
  }
  .title-inner {
    grid-row: 2;
    grid-template-rows: auto;
    height: auto;
    position: static;
  }
  .title-inner > * {
    position: relative;
    z-index: 3;
  }
  .title-inner > .title-head {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    left: clamp(16px, 4vw, 56px);
    z-index: 2;
  }
  .t-allstar {
    font-size: clamp(36px, 9vw, 80px);
  }
  .t-kassen {
    font-size: clamp(64px, 16vw, 150px);
  }
  .title-logo h1 {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 0.2em;
  }
}
@media (max-width: 700px) {
  .menu-row {
    grid-template-columns: 1fr;
  }
  .menu-sub {
    min-height: 48px;
    grid-auto-flow: column;
    justify-content: space-between;
    align-items: center;
  }
  .title-lead br {
    display: none;
  }
}
@media (max-height: 560px) {
  .title-lead br {
    display: none;
  }
  .menu-sub small {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- カードの詳しい説明（左にカード、右に数値と効果。横長） ---------- */
.detail {
  position: relative;
  text-align: left;
  max-height: 92dvh;
  max-width: min(860px, 94vw);
  width: 94vw;
  padding: 22px;
}
#detail-content {
  display: grid;
  grid-template-columns: minmax(160px, 36%) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
.detail-art {
  display: grid;
  gap: 10px;
  justify-items: center;
  position: sticky;
  top: 0;
}
#detail-content .detail-art img {
  width: 100%;
  max-width: 300px;
  margin: 0;
  border-radius: 12px;
  box-shadow: 0 12px 28px #0005;
}
.detail-back {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 63 / 88;
  border-radius: 12px;
  background: url('/img/card-back.webp') center / cover;
  box-shadow: 0 12px 28px #0005;
}
.stack-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: bold;
  color: var(--navy);
}
.stack-nav .nav {
  width: 48px;
  height: 44px;
  border: 2px solid var(--navy);
  border-radius: 10px;
  background: white;
  color: var(--navy);
  font-size: 18px;
}
.stack-nav .nav:disabled {
  opacity: 0.3;
}
.detail-info {
  min-width: 0;
}
.detail-info h2 {
  margin: 4px 40px 8px 0;
  text-align: left;
  font-size: 28px;
}
.detail-info .detail-meta {
  justify-content: flex-start;
}
.detail-meta .tag-set {
  background: var(--navy);
  color: white;
}
.detail-effect.usable {
  background: #fff4d6;
  box-shadow: inset 0 0 0 2px var(--gold);
}
.detail-effect .use {
  margin-top: 10px;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(#d4553a, var(--accent-deep));
  color: white;
  font-size: 18px;
  font-weight: bold;
  box-shadow: 0 4px 0 #6e200f;
}
.detail-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.detail-actions .act {
  min-height: 50px;
  border: 2px solid var(--navy);
  border-radius: 12px;
  background: var(--navy);
  color: white;
  font-size: 17px;
  font-weight: bold;
}
@media (max-width: 600px), (max-aspect-ratio: 3/4) {
  #detail-content {
    grid-template-columns: 1fr;
  }
  #detail-content .detail-art img,
  .detail-back {
    max-width: 200px;
  }
  .detail-art {
    position: static;
  }
}
/* 長押しで、端末のメニュー（画像の保存など）が出ないように */
.card {
  -webkit-touch-callout: none;
}

/* アタッカー（剣）・ブロッカー（盾）のマーク */
.detail-meta .role-mark {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 10px;
  color: white;
}
.role-mark svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.detail-meta .role-attacker {
  background: var(--accent);
}
.detail-meta .role-blocker {
  background: #2f6db5;
}
.detail-meta .role-both {
  background: linear-gradient(90deg, var(--accent), #2f6db5);
}

/* 音の設定 */
.title-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sound-btn {
  min-height: 44px;
  padding: 6px 16px;
  border: 2px solid var(--navy);
  border-radius: 999px;
  background: #fffaf0e8;
  color: var(--navy);
  font-weight: bold;
}
.sound-dialog {
  position: relative;
  text-align: left;
  max-width: min(440px, 92vw);
}
.sound-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.sound-row input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  height: 32px;
}
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: bold;
  font-size: 17px;
  cursor: pointer;
}
.switch input {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
}
.sound-note {
  font-size: 13px;
  color: var(--ink-soft);
}
/* タイトルの音の設定は、画面の右上に */
.title .sound-btn {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  z-index: 5;
}
