* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #4f9a38;
  font: 500 14px/1.3 ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
canvas#game {
  display: block; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  touch-action: none;
}
.overlay { position: fixed; z-index: 10; }
[hidden] { display: none !important; }

/* 右上の札 */
.tools {
  top: calc(54px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  display: flex; gap: 6px; align-items: center; z-index: 12;
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #ffbe0b; outline-offset: 2px; }
.round, .lang {
  height: 36px; background: rgba(28, 37, 65, .82); color: #fff;
  border: 1px solid rgba(255, 255, 255, .45); border-radius: 18px;
}
.round { width: 36px; padding: 0; display: flex; align-items: center; justify-content: center; }
.round .off-mark, .round.off .on-mark { display: none; }
.round.off .off-mark { display: inline; }
.round.off { color: #c3c9dc; }
.lang { display: flex; gap: 2px; padding: 3px; font-weight: 800; font-size: 12px; }
.lang span {
  display: flex; align-items: center; justify-content: center;
  min-width: 36px; height: 28px; padding: 0 8px; border-radius: 14px; opacity: .65; white-space: nowrap;
}
.lang span.on { background: #fff; color: #1c2541; opacity: 1; }

/* 走っている間は感想の丸を薄くする（ux.md） */
body.running .dafb-btn { opacity: .55; }

/* 画面の層。札は下に寄せ、自分の恐竜（上から約 38%）を隠さない */
.screen {
  top: 0; bottom: 0; left: 50%; width: 100%; max-width: 480px; transform: translateX(-50%);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 0 14px calc(18px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
.card {
  pointer-events: auto; width: 100%; max-width: 380px; text-align: center; color: #fff;
  background: rgba(28, 37, 65, .94); border: 2px solid rgba(255, 255, 255, .35); border-radius: 22px;
  padding: 16px 16px 16px; box-shadow: 0 8px 28px rgba(10, 30, 10, .35);
}
.card h1 { margin: 0; font-size: clamp(24px, 7.4vw, 30px); font-weight: 900; line-height: 1.2; color: #ffd60a; }
.card h2 { margin: 0; font-size: 26px; font-weight: 900; }
.card p { margin: 8px 0 0; font-weight: 700; }
.primary {
  display: block; width: 100%; margin-top: 14px; min-height: 62px; padding: 10px 16px;
  font-size: 24px; font-weight: 900; color: #1c2541; background: #ffbe0b;
  border: 0; border-radius: 31px; box-shadow: 0 5px 0 #b9860a;
}
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #b9860a; }
.title { padding-bottom: calc(clamp(18px, 7vh, 70px) + env(safe-area-inset-bottom, 0px)); }
.title .card p { white-space: pre-line; }

.title .link {
  margin-top: 12px; min-height: 36px; padding: 4px 22px; color: #fff; background: transparent;
  border: 1px solid rgba(255, 255, 255, .55); border-radius: 18px; font-weight: 800;
}

/* 結果の画面: 画面いっぱい。1枚の絵が残りの高さを使い、次の1手は下に大きく1つ。上の帯の高さは札の列 */
.screen.result {
  pointer-events: auto; justify-content: flex-start; color: #fff; background: #1c2541; text-align: center;
  padding: calc(48px + env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto; overscroll-behavior: contain;
}
.result > * { flex: 0 0 auto; width: 100%; max-width: 420px; }
.result p { margin: 4px 0 0; font-weight: 700; line-height: 1.3; }
.result .band { margin: 0; padding: 6px 12px; font-size: 24px; font-weight: 900; border-radius: 14px; background: #5b6275; }
.result[data-outcome="advance"] .band { background: #1d7a46; }
.result[data-outcome="win"] .band { background: #ffbe0b; color: #1c2541; }
.result .facts { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0 12px; font-size: 13px; }
.result .facts strong { font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }
.result .place { font-size: 15px; color: #ffd60a; }
.result .place .gap-note { display: inline-block; margin-left: .5em; }
.result .shot { flex: 1 0 250px; min-height: 250px; position: relative; margin-top: 6px; }
.result .shot img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto;
}
.result .shot img:not([src]) { visibility: hidden; }
.result .why { font-size: 13px; }
.result .best { font-size: 13px; color: #cfe0ff; }
.result .best.new { color: #1c2541; background: #ffd60a; border-radius: 10px; padding: 2px 8px; }
.result .last { font-size: 12px; opacity: .85; }
.notice { font-size: 12px; color: #ffb4a8; }
.cup { display: flex; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.cup li { flex: 1; display: flex; flex-direction: column; padding: 3px 2px; border-radius: 10px; background: #39426b; font-size: 11px; font-weight: 700; }
.cup li b { font-size: 14px; font-variant-numeric: tabular-nums; }
.cup li.ok { background: #1d7a46; }
.cup li.ng { background: #7a4a45; }
.cup li.none { opacity: .55; }
.suit { display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 8px; }
.suit button { width: 30px; height: 32px; flex: 0 1 30px; padding: 0; border: 2px solid rgba(255, 255, 255, .35); }
.suit .dot { border-radius: 16px; background: var(--c); }
.suit .swatch { border-radius: 8px; background-color: var(--c); }
.suit .swatch.p1 { background-image: repeating-linear-gradient(0deg, #fff 0 4px, transparent 4px 9px); }
.suit .swatch.p2 { background-image: radial-gradient(circle, #fff 0 2.6px, transparent 3.2px); background-size: 10px 10px; }
.suit button.on { border-color: #fff; box-shadow: 0 0 0 3px #ffbe0b; }
.suit .gap { width: 8px; }
.minor { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.minor button {
  flex: 1; min-height: 38px; padding: 4px 6px; color: #fff; background: #39426b; font-size: 13px; font-weight: 800;
  border: 1px solid rgba(255, 255, 255, .4); border-radius: 19px; line-height: 1.15;
}
.minor button:disabled { opacity: .5; }
.minor button { flex: 1 1 auto; white-space: nowrap; }
/* 優勝の締めは札が5つ。1行に収まる字にする */
.result[data-outcome="win"] .minor { gap: 4px; }
.result[data-outcome="win"] .minor button { font-size: 11px; padding-left: 3px; padding-right: 3px; }
.result .primary { margin-top: 10px; margin-bottom: 5px; }

/* 記録の画面 */
.screen.records { justify-content: center; padding-top: 48px; background: rgba(10, 20, 30, .55); }
.records .card { pointer-events: auto; max-height: 100%; overflow-y: auto; }
.records .list { margin: 8px 0 0; padding: 0; list-style: none; text-align: left; }
.records .list li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 4px; border-bottom: 1px solid rgba(255, 255, 255, .16); font-size: 14px; }
.records .list li b { font-variant-numeric: tabular-nums; text-align: right; }
.records .list li.top b { color: #ffd60a; }
.records .list li.head { border-bottom: 0; margin-top: 5px; font-weight: 900; color: #ffd60a; font-size: 13px; }
.records .label { font-size: 13px; }
.records .suit { margin-top: 5px; }
.lite { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-weight: 800; }
.lite button { width: 66px; min-height: 34px; color: #fff; background: #39426b; border: 2px solid rgba(255, 255, 255, .45); border-radius: 17px; font-weight: 900; }
.lite button.on { background: #ffbe0b; color: #1c2541; }
.records .card .note { margin-top: 3px; font-size: 12px; opacity: .85; text-align: left; }

/* 紙ふぶき、読み込み中、知らせ */
.copy-helper { position: fixed; left: 0; top: 0; opacity: 0; }
#confetti { position: fixed; top: 0; left: 0; width: 100vw; height: 100%; z-index: 20; pointer-events: none; }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; opacity: 0; animation: appear .2s 1s forwards; }
#loading span { width: 96px; height: 120px; border-radius: 50% 50% 44% 44%; background: rgba(16, 35, 15, .4); transform-origin: 50% 100%; animation: breathe 1.6s ease-in-out infinite; }
@keyframes appear { to { opacity: 1; } }
@keyframes breathe { 0%, 100% { transform: scale(1.35, .3); } 55% { transform: scale(1, 1); } }
#toast {
  position: fixed; left: 50%; top: 104px; transform: translateX(-50%); z-index: 2147483647; margin: 0;
  width: min(340px, calc(100% - 28px)); padding: 10px 14px; text-align: center; font-weight: 800;
  color: #fff; background: #1c2541; border: 2px solid #ffbe0b; border-radius: 14px; pointer-events: none;
}
.result p.copied { font-size: 13px; color: #ffd60a; margin-top: 6px; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }

/* 結果の画面から開いた記録は、後ろの走りの帯を見せない */
body[data-state="result"] .screen.records { background: #1c2541; }

/* 結果と記録の画面では、右上の札を上の端へ（絵と文に重ねない） */
body[data-state="result"] .tools { top: calc(8px + env(safe-area-inset-top, 0px)); }
body[data-panel="records"] .tools { top: calc(8px + env(safe-area-inset-top, 0px)); }

.pause { justify-content: center; padding-top: 30vh; background: rgba(10, 20, 30, .35); }

@media (max-height: 700px) {
  .card { padding: 12px 14px 13px; }
  .card p { margin-top: 5px; font-size: 13px; }
  .primary { min-height: 54px; margin-top: 10px; font-size: 21px; }
  .title .link { margin-top: 10px; min-height: 32px; }
  .screen.result { padding-top: calc(46px + env(safe-area-inset-top, 0px)); padding-bottom: 8px; }
  .result .band { padding: 3px 10px; font-size: 20px; }
  .result p { margin-top: 2px; }
  .result .facts { font-size: 12px; }
  .result .facts strong { font-size: 16px; }
  .result .place { font-size: 13px; }
  .result .why, .result .best { font-size: 12px; }
  .result .last { font-size: 11px; }
  .result .shot { flex-basis: 210px; min-height: 210px; margin-top: 4px; }
  .result .suit { margin-top: 5px; }
  .result .suit button { height: 28px; }
  .result .minor { margin-top: 7px; }
  .result .minor button { min-height: 32px; font-size: 12px; }
  .result .primary { min-height: 50px; margin-top: 7px; margin-bottom: 4px; }
  .records .list li { padding: 1px 4px; font-size: 13px; }
}
@media (min-aspect-ratio: 3/4) and (min-width: 481px) {
  .tools { right: calc((100vw - 480px) / 2 + 8px); }
}
.no-ui .overlay { display: none; }
