:root {
  color-scheme: light;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  color: #1b2927;
  background: #f5f4ed;
  --ink: #1b2927;
  --muted: #52615a;
  --line: #d8ddd2;
  --surface: #fffefa;
  --green: #225b43;
  --lime: #d9f784;
  --radius: 18px;
  --page-gutter: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --page-left: max(var(--page-gutter), calc(var(--safe-left) + 6px));
  --page-right: max(var(--page-gutter), calc(var(--safe-right) + 6px));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, canvas:focus-visible {
  outline: 3px solid #347850;
  outline-offset: 3px;
}

.site-header { border-bottom: 1px solid var(--line); padding-top: var(--safe-top); }
.header-inner, .page {
  max-width: calc(1160px + var(--page-left) + var(--page-right));
  margin-inline: auto;
  padding-inline: var(--page-left) var(--page-right);
}

.header-inner {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 44px;
  gap: 9px;
  border: 0;
  background: none;
  color: var(--ink);
  padding: 0;
  text-align: start;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  border-radius: 11px;
  background: var(--ink);
  color: var(--lime);
  font: 900 24px/1 "Arial Black", system-ui, sans-serif;
  letter-spacing: -0.08em;
  padding-inline-end: 2px;
}

.brand-name {
  font: 950 13px/0.92 "Arial Black", system-ui, sans-serif;
  letter-spacing: 0.025em;
}

.player-badge {
  min-width: 0;
  min-height: 44px;
  max-width: 390px;
  padding: 5px 13px 5px 6px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.91rem;
  font-weight: 750;
  text-align: start;
}

.player-badge:hover { border-color: #758d78; }
.player-badge:has(#player-title[hidden]) { padding-inline-end: 6px; }
.player-badge img {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 50%;
  background: #e7efe1;
}

#player-title {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--green);
  font-size: 0.75rem;
  line-height: 1.2;
}

.page { padding-block: 35px max(36px, calc(var(--safe-bottom) + 12px)); }
.hero {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 0.95fr);
  align-items: center;
  min-height: 390px;
  overflow: hidden;
  border: 1px solid #cbd9c6;
  border-radius: 25px;
  background: #e7efdf;
}

.hero-copy { padding: clamp(24px, 4.5vw, 64px); position: relative; z-index: 1; }
.hero-copy h1 {
  margin: 0;
  font: 950 clamp(55px, 8.3vw, 125px)/0.81 "Arial Black", system-ui, sans-serif;
  letter-spacing: -0.092em;
}

.hero-copy h1 > span { display: block; white-space: nowrap; }
.hero-copy h1 > span + span { color: var(--green); margin-top: 0.085em; }
.hero-dot { color: #72a442; }
.hero-copy p {
  margin: 26px 0 0;
  color: #425848;
  font-size: clamp(0.91rem, 1.6vw, 1.15rem);
  font-weight: 750;
  letter-spacing: 0.025em;
}

.hero-art {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 0;
  min-height: 325px;
  overflow: hidden;
  position: relative;
  isolation: isolate;
  background: radial-gradient(ellipse at 46% 51%, #e0f8a9 0%, #d6edb9 38%, transparent 71%);
}

.hero-art::before {
  content: "";
  position: absolute;
  inset: -10% -8%;
  background-image: radial-gradient(#557549 0.75px, transparent 0.75px);
  background-size: 13px 13px;
  mask-image: radial-gradient(ellipse at center, #000 3%, transparent 71%);
  opacity: 0.38;
}

.hero-stage {
  width: min(100%, 440px);
  height: min(100%, 390px);
  min-height: 270px;
  position: relative;
}

.hero-guide {
  position: absolute;
  left: 13%;
  top: 8%;
  width: 67%;
  height: 76%;
  border: 1px dashed #6e955a;
  border-radius: 50%;
  transform: rotate(-26deg);
  opacity: 0.6;
}

.hero-piece {
  position: absolute;
  display: block;
  width: 36%;
  height: 39%;
  object-fit: contain;
  filter: drop-shadow(0 8px 0 #295a4330);
}

.hero-piece-one { left: 25%; bottom: 19%; transform: rotate(-11deg); z-index: 2; }
.hero-piece-two { left: 43%; bottom: 40%; transform: rotate(17deg); z-index: 3; }
.hero-piece-three { left: 29%; bottom: 60%; transform: rotate(-18deg); z-index: 1; }
.hero-platform {
  position: absolute;
  left: 19%;
  bottom: 13%;
  width: 58%;
  height: 7%;
  border: 3px solid #1c3c32;
  border-radius: 7px;
  background: var(--lime);
  box-shadow: 0 6px 0 #1c3c32;
}

.hero-shadow {
  position: absolute;
  left: 22%;
  bottom: 7%;
  width: 51%;
  height: 12%;
  border-radius: 50%;
  background: #2e69433d;
}

.mode-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 19px;
}

.mode {
  min-height: 111px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(9px, 1.55vw, 18px);
  padding: clamp(11px, 1.65vw, 20px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: start;
  transition: border-color 150ms, translate 150ms, box-shadow 150ms;
}

.mode:hover { translate: 0 -3px; border-color: #839b85; box-shadow: 0 7px 20px #1b29270d; }
.mode:active { translate: 0 1px; }
.mode-versus {
  min-width: 0;
  align-self: stretch;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 10px;
  border: 1px solid #d9cee7;
  border-radius: var(--radius);
  background: #f3edf9;
}

.mode-versus h2 { margin: 0 2px; color: #4d3966; font-size: 0.92rem; }
.versus-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.versus-choice {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 56px;
  padding: 5px;
  border: 1px solid #c9b8db;
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  text-align: start;
}

.versus-choice:hover { background: #fff; border-color: #8467a1; }
.versus-choice .mode-symbol { flex: none; width: clamp(26px, 3.4vw, 44px); }
.versus-choice .mode-content { gap: 2px; }
.versus-choice .mode-content strong { font-size: 0.94rem; }
.versus-choice .mode-content span { font-size: 0.72rem; }
.cpu-symbol { background: #e9e2f5; }
.mode-symbol {
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  width: clamp(40px, 5vw, 61px);
  aspect-ratio: 1;
  border-radius: 12px;
  font: 800 1.55rem/1 system-ui, sans-serif;
}

.mode-symbol img {
  position: absolute;
  width: 74%;
  height: auto;
  object-fit: contain;
}

.practice-symbol { background: #e0eed5; }
.practice-symbol img { inset: 2% auto auto 13%; }
.practice-symbol::after {
  content: "";
  position: absolute;
  inset: auto 12% 14%;
  height: 15%;
  border: 1px solid #2e5f42;
  border-radius: 3px;
  background: var(--lime);
  box-shadow: 0 2px #2e5f42;
}

.versus-symbol { color: #514085; background: #eae4f8; }
.versus-symbol:has(img)::before {
  content: "";
  position: absolute;
  inset: 12% auto 12% 50%;
  border-inline-start: 2px solid #fffefa;
  transform: rotate(23deg);
}
.versus-symbol img { width: 62%; }
.versus-symbol img:first-child { inset: 1% auto auto 0; transform: rotate(-10deg); }
.versus-symbol img:last-child { inset: auto 0 1% auto; transform: rotate(10deg); }

.challenge-symbol { background: #f7eccd; }
.challenge-symbol img { inset: auto auto 4% 0; }
.challenge-symbol::before {
  content: "";
  position: absolute;
  inset: 13% 12% 16% 49%;
  border-radius: 2px;
  background: #bd852c;
  clip-path: polygon(0 100%, 0 64%, 28% 64%, 28% 100%, 36% 100%, 36% 33%, 64% 33%, 64% 100%, 72% 100%, 72% 0, 100% 0, 100% 100%);
}

.mode-content { display: grid; gap: 6px; line-height: 1.25; }
.mode-content strong { font-size: clamp(0.99rem, 1.9vw, 1.36rem); font-weight: 850; }
.mode-content span { color: var(--muted); font-size: 0.78rem; }

.play-heading {
  margin: -3px 0 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.play-heading h1 { margin: 0; font-size: clamp(1.3rem, 2.6vw, 2.2rem); flex: none; }
.opponent-profile {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
  padding: 2px 8px 2px 2px;
  border-radius: 999px;
  background: #fff8e9;
  color: #354f46;
  font-size: 0.85rem;
  font-weight: 700;
}
.opponent-profile img {
  flex: none;
  border-radius: 50%;
  object-fit: cover;
}
.opponent-profile span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#clear-practice {
  min-height: 44px;
  padding: 0 0 0.1em;
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: inherit;
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

#clear-practice:not(:disabled):hover { text-decoration-style: solid; }
.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 320px);
  gap: 18px;
  align-items: start;
}

.board-column { display: grid; gap: 8px; min-width: 0; }
.board {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-width: 0;
  border: 1px solid #b9cdb5;
  border-radius: var(--radius);
  background: #edf4e7;
  color: var(--ink);
}

.board-stage {
  position: relative;
  background: linear-gradient(to bottom, #d8dfd0 62.5%, #c8bfa9 62.5%);
}

.board-heading {
  display: flex;
  position: absolute;
  inset: 14px 14px auto;
  z-index: 1;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

#board-status, #turn-clock {
  min-height: 31px;
  padding: 6px 11px;
  border: 1px solid #b9cdb5;
  border-radius: 40px;
  background: #f3f8ec;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 720;
}

#board-status { margin-inline-end: auto; }
#turn-clock { flex: none; font-variant-numeric: tabular-nums; }
#turn-clock.urgent { border-color: #d9ac72; background: #fff0d5; color: #78451e; }
#board-canvas {
  display: block;
  width: min(100%, 485px, 53dvh);
  height: auto;
  margin-inline: auto;
  touch-action: pinch-zoom;
  cursor: crosshair;
}

#board-canvas:focus-visible { outline-offset: -3px; }
.board-overlay {
  display: grid;
  place-items: safe center;
  position: absolute;
  inset: 0;
  padding: 42px 16px 16px;
  overflow-y: auto;
  background: #edf4e7bf;
  z-index: 2;
}

.board-message {
  width: min(100%, 320px);
  padding: 24px;
  border: 1px solid #b9cdb5;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 12px #225b431c;
  text-align: center;
}

.result-heading:has(img:not([hidden])) {
  display: grid;
  grid-template-columns: clamp(48px, 16vw, 76px) minmax(0, 1fr);
  align-items: center;
  column-gap: 4px;
  margin-bottom: 8px;
}

.result-heading:has(#overlay-result-right:not([hidden])) {
  grid-template-columns: clamp(48px, 16vw, 76px) minmax(0, 1fr) clamp(48px, 16vw, 76px);
}

.result-heading:has(img:not([hidden])) h2 { margin: 0; }
.result-heading img { width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; }
#overlay-result-right { transform: scaleX(-1); }
#overlay-record {
  display: inline-block;
  margin-bottom: 6px;
  padding: 3px 10px;
  border: 1px solid #d5a326;
  border-radius: 8px;
  color: #614208;
  background: #fff0b8;
  font-size: clamp(1rem, 4.2vw, 1.2rem);
  font-weight: 850;
}

.board-message h2 { margin: 0 0 12px; color: var(--green); font-size: clamp(1.25rem, 4vw, 1.5rem); text-wrap: balance; }
.board-message p { margin: 0 0 18px; color: var(--muted); font-size: 0.87rem; line-height: 1.65; white-space: pre-line; }
.board-message :is(.quiet-button, .secondary-button) { margin-top: 5px; }
#overlay-rematch-status { margin: 6px 0 0; }
.board-overlay[data-online-result]:not([hidden]) ~ .emote-effects { z-index: 3; }
.board-overlay[data-online-result]:not([hidden]) ~ .emote-reactions { z-index: 4; }
.board-overlay[data-online-result]:not([hidden]) ~ .board-picker { z-index: 5; }
.game-side { display: grid; gap: 14px; }
.game-side:not(:has(.control-panel:not([hidden]) > :not([hidden]))) { display: none; }
.game-side > .control-panel:first-child:not(:has(> :not([hidden]))) { display: none; }
.control-panel {
  padding: 15px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
}

.stats { display: flex; gap: 12px; }
.stats > div {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 3px;
}

.stats span { font-size: 0.73rem; color: var(--muted); font-weight: 750; }
.stats strong { font-size: 1.68rem; line-height: 1.08; font-variant-numeric: tabular-nums; }
#next-piece { object-fit: contain; width: 32px; height: 28px; }

#pose-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  white-space: nowrap;
}

#current-piece { object-fit: contain; }

.controls { display: flex; gap: 6px; touch-action: manipulation; }

:where(.controls) > button, .primary-button, .secondary-button, .quiet-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 800;
}

.controls [data-adjust] {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  border-color: #c9c4d8;
  background: #f0ecf7;
  color: var(--ink);
  padding: 0;
}

.controls [data-adjust]:not(:disabled):hover { border-color: #9e95b7; background: #e7dff4; }
.controls [data-adjust] svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.controls [data-adjust="clockwise"] svg { transform: scaleX(-1); }
.controls .primary-button { flex: 1; min-width: 64px; padding-inline: 5px; }

#emote-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  padding: 4px;
}

#emote-toggle img { display: block; object-fit: contain; }
#emote-toggle[aria-expanded="true"], #pose-toggle[aria-expanded="true"] {
  border-color: #6e9378;
  background: #e1efd9;
}
#emote-toggle[aria-disabled="true"] { opacity: 0.65; cursor: wait; }
.primary-button, .secondary-button, .quiet-button { padding: 8px 13px; font-size: 0.88rem; }
.primary-button {
  color: #213721;
  border-color: #a3bc5b;
  background: var(--lime);
}

.primary-button:not(:disabled):hover { background: #e8ffad; border-color: #6b953b; }
.secondary-button {
  border-color: #acc1af;
  color: var(--green);
  background: #edf4ea;
}

.secondary-button:not(:disabled):hover { border-color: #6e9378; background: #e1efd9; }
.quiet-button { color: var(--green); background: transparent; }
.quiet-button:not(:disabled):hover { background: #e7efe1; }
button:disabled { opacity: 0.55; }

.play-error {
  margin: 10px 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
}

.play-error, .profile-message.error { color: #9b342f; }
.icon-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.board-picker {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 8px;
  background: #5c765449;
  touch-action: manipulation;
}

.picker-sheet {
  display: grid;
  width: min(100%, 360px);
  max-height: 100%;
  max-block-size: 100%;
  gap: 4px;
  justify-items: end;
  padding: 8px;
  border: 1px solid #a7bcaa;
  border-radius: 12px;
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.picker-options {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 4px;
  padding: 3px;
}

#pose-picker, .emote-picker > .picker-options { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.emote-picker { display: grid; width: 100%; gap: 4px; }
.emote-picker > :first-child { border-bottom: 1px solid var(--line); padding-bottom: 7px; }
#practice-poses h2 { margin: 0 0 8px; color: var(--green); font-size: 1rem; }
#practice-poses #pose-picker {
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  max-height: max(148px, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 180px));
  overflow-y: auto;
}
.picker-sheet .quiet-button { padding: 4px 10px; font-size: 0.8rem; }

.pick-piece, .pick-emote, .pick-icon, .pick-emote-character {
  display: grid;
  place-items: center;
  gap: 1px;
  min-width: 0;
  min-height: 46px;
  padding: 4px 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f5ed;
  color: var(--ink);
  line-height: 1.2;
  text-align: center;
}

.pick-piece img, .pick-emote img, .pick-icon img, .pick-emote-character img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
}

:is(.pick-piece, .pick-emote) img { max-width: 42px; }
.pick-emote-character img { max-width: 32px; }
:is(.pick-piece, .pick-icon, .pick-emote, .pick-emote-character):not(:disabled):hover { border-color: #839b85; }
:is(.pick-piece, .pick-icon, .pick-emote-character)[aria-pressed="true"] { border-color: #608c42; background: #e9f5ce; }
.emote-reactions, .emote-effects {
  --emote-size: clamp(48px, 17vw, 76px);
  position: absolute;
  inset: auto 8px 12%;
  pointer-events: none;
}

.emote-effects { z-index: 0; }

.emote-reactions {
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-content: space-between;
  align-items: end;
}

.emote-reaction {
  display: grid;
  justify-items: start;
  align-items: end;
}

.emote-opponent { justify-items: end; }
.emote-pop {
  position: relative;
  grid-area: 1 / 1;
  width: var(--emote-size);
  pointer-events: none;
}

.emote-pop > img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* 画像だけを反転し、外側の入退場 transform と独立させる。 */
.emote-opponent .emote-pop > img { transform: scaleX(-1); }

.emote-effect {
  --emote-direction: 1;
  --effect-anchor: calc(var(--emote-size) * 0.86);
  position: absolute;
  inset-block-end: calc(var(--emote-size) * 0.77);
  inset-inline-start: var(--effect-anchor);
  display: grid;
  place-content: center;
  place-items: center;
  width: 0;
  height: 0;
  font-size: clamp(19px, 6vw, 31px);
  line-height: 1;
  font-weight: 900;
  color: #ffdc62;
  -webkit-text-stroke: 1px #493221;
  animation: emote-effect-fade 1500ms ease-in forwards;
}

.emote-effect-opponent {
  --emote-direction: -1;
  inset-inline: auto var(--effect-anchor);
}

.emote-effect > span {
  grid-area: 1 / 1;
  filter: drop-shadow(0 1px 1px #372a2aea);
}

.emote-effect[data-effect="heart"] { color: #xff82a2; }
.emote-effect:is([data-effect="sweat"], [data-effect="thumbs-up"], [data-effect="confusion"]) {
  -webkit-text-stroke: 0;
}

.emote-effect:is([data-effect="heart"], [data-effect="star"], [data-effect="sweat"], [data-effect="thumbs-up"]) > span {
  --effect-dx: calc(var(--effect-x) * var(--emote-direction));
  transform: translate(var(--effect-dx), var(--effect-y)) scale(var(--effect-scale));
  animation: emote-effect-burst 480ms cubic-bezier(0.18, 0.78, 0.32, 1) var(--effect-delay) backwards;
}

.emote-effect > :nth-child(1) {
  --effect-x: 0.28em;
  --effect-y: -1.32em;
  --effect-scale: 0.8;
  --effect-delay: 70ms;
}

.emote-effect > :nth-child(2) {
  --effect-x: 1.44em;
  --effect-y: -0.65em;
  --effect-scale: 1;
  --effect-delay: 125ms;
}

.emote-effect > :nth-child(3) {
  --effect-x: 1.32em;
  --effect-y: 0.57em;
  --effect-scale: 0.61;
  --effect-delay: 180ms;
}

.emote-effect[data-effect="sweat"] > :nth-child(1) { --effect-y: -0.68em; }
.emote-effect[data-effect="sweat"] > :nth-child(2) { --effect-y: 0; }
.emote-effect[data-effect="sweat"] > :nth-child(3) { --effect-y: 0.84em; }

.emote-effect:is([data-effect="confusion"], [data-effect="surprise"]) > span {
  translate: calc(0.7em * var(--emote-direction)) 0;
}

.emote-effect[data-effect="confusion"] > span {
  animation: emote-effect-spin 1200ms linear 85ms backwards;
}

.emote-effect[data-effect="surprise"] > span {
  animation: emote-effect-bounce 560ms ease-out 80ms backwards;
  rotate: calc(13deg * var(--emote-direction));
}

@keyframes emote-effect-fade {
  0%, 74% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes emote-effect-burst {
  from { opacity: 0; transform: scale(0.35); }
  25% { opacity: 1; }
  to { transform: translate(var(--effect-dx), var(--effect-y)) scale(var(--effect-scale)); }
}

@keyframes emote-effect-spin {
  from { opacity: 0; transform: rotate(0); }
  14% { opacity: 1; }
  to { transform: rotate(360deg); }
}

@keyframes emote-effect-bounce {
  0% { opacity: 0; transform: translateY(1.25em) scale(0.65); }
  42% { opacity: 1; transform: translateY(-0.3em) scale(1.13); }
  68% { transform: translateY(0.11em) scale(0.94); }
  100% { transform: translateY(0) scale(1); }
}

.keyboard-guide { margin: 12px 0 0; color: var(--muted); font-size: 0.76rem; }
kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  margin-inline-end: 3px;
}

#profile-dialog {
  --dialog-top: max(10px, calc(var(--safe-top) + 6px));
  --dialog-bottom: max(10px, calc(var(--safe-bottom) + 6px));
  --dialog-left: max(10px, calc(var(--safe-left) + 6px));
  --dialog-right: max(10px, calc(var(--safe-right) + 6px));
  --dialog-padding: clamp(12px, 4vw, 27px);
  position: fixed;
  inset: var(--dialog-top) var(--dialog-right) var(--dialog-bottom) var(--dialog-left);
  width: min(calc(100% - var(--dialog-left) - var(--dialog-right)), 570px);
  max-width: none;
  height: min(760px, calc(100dvh - var(--dialog-top) - var(--dialog-bottom)));
  max-height: none;
  padding: 0;
  border: 1px solid #adbead;
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  overflow: hidden;
}

dialog::backdrop { background: #142d25a6; }
body:has(dialog[open]) { overflow: hidden; }
.dialog-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.dialog-header {
  flex: none;
  padding: 8px var(--dialog-padding);
  border-bottom: 1px solid var(--line);
}

#profile-dialog [role="tabpanel"], .profile-edit-fields {
  flex: 1;
  min-height: 0;
}

#profile-dialog [role="tabpanel"]:not(#profile-edit), .profile-edit-fields {
  padding: 14px var(--dialog-padding) var(--dialog-padding);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 14px;
}

#profile-edit {
  display: flex;
  flex-direction: column;
}
.profile-edit-footer {
  display: grid;
  flex: none;
  justify-content: end;
  padding: 8px var(--dialog-padding);
  border-top: 1px solid var(--line);
}
#profile-heading { margin: 0; font-size: 1.37rem; }

form > label, .save-section label, legend {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 750;
}

input, select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid #b6c4b5;
  border-radius: 8px;
  background: #fdfefb;
  color: var(--ink);
  padding: 7px 8px;
}

fieldset {
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 14px 0 0;
}

legend { padding: 0; }
.pick-icon img { width: min(100%, 45px); }
.profile-tabs {
  display: grid;
  grid-template-columns: minmax(max-content, 1.7fr) 1fr 1fr;
  gap: 4px;
  margin-top: 8px;
  padding: 4px;
  border-radius: 11px;
  background: #eef1e8;
}

.profile-tabs button {
  min-height: 44px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
}

.profile-tabs [aria-selected="true"] { background: #fffefa; border-color: #b8c6b2; color: var(--green); }
.profile-summary {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 80px;
  gap: 12px;
  margin-top: 8px;
  padding: 9px 12px;
  border: 1px solid #cddbc4;
  border-radius: 12px;
  background: #edf4e6;
  line-height: 1.25;
}

.profile-summary img { flex: none; border-radius: 50%; background: #e1ebd8; object-fit: contain; }
.profile-title {
  min-width: 0;
  margin: 0;
  color: var(--green);
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.profile-icon-groups { display: grid; gap: 12px; padding: 9px; border: 1px solid var(--line); border-radius: 9px; }
.round-icon-groups { display: grid; gap: 9px; padding-top: 9px; border-top: 1px solid var(--line); }
#profile-dialog .round-icon-groups .icon-picker { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.round-icon-groups .icon-picker + .icon-picker { padding-top: 9px; border-top: 1px solid var(--line); }
.profile-titles { display: grid; gap: 8px; margin: 0 0 14px; }
#random-title { justify-self: start; }
.title-inputs { display: grid; grid-template-columns: 1fr 0.85fr 1fr; gap: 6px; }
.title-inputs select { padding-inline: 5px; font-size: 0.875rem; }
.profile-records {
  margin-block: 0 16px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f4f7f0;
  overflow-wrap: anywhere;
}

.profile-records table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 0.88rem; }
.profile-records th, .profile-records td { padding: 5px 3px; text-align: end; }
.profile-records tr > :first-child { width: 58%; padding-inline-start: 0; text-align: start; }
.profile-records tr > :last-child { padding-inline-end: 0; }
.profile-records thead th { color: var(--muted); font-size: 0.78rem; }
.profile-records tbody td, .profile-best strong { font-size: 1rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.profile-best {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}

.reset-button {
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid #be8d7b;
  border-radius: 10px;
  background: #faece6;
  color: #862e1a;
  font-size: 0.88rem;
  font-weight: 800;
}

.reset-button:hover:not(:disabled) { border-color: #a85c43; background: #f8e1d7; }
#reset-confirmation { padding: 10px; border: 1px solid #be8d7b; border-radius: 10px; }
#reset-question { margin: 0 0 10px; font-size: 0.88rem; }
.reset-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.save-section p { margin: 0 0 8px; font-size: 0.8rem; color: var(--muted); line-height: 1.55; }
.inline-action { display: flex; align-items: stretch; gap: 6px; }
.inline-action > button { flex: none; }
#own-code { font: 600 0.93rem/1.4 ui-monospace, Consolas, monospace; letter-spacing: 0.04em; }
details { margin-top: 11px; }
summary { width: fit-content; min-height: 44px; padding-block: 11px; cursor: pointer; color: var(--green); font-size: 0.87rem; font-weight: 800; }
details form { margin-top: 9px; }
p.profile-message { margin: 0; color: var(--green); font-size: 0.85rem; }
.profile-message:not(:empty) { margin-bottom: 10px; }

@media (max-width: 870px) {
  :root { --page-gutter: 16px; }
  .hero { min-height: 320px; }
  .hero-copy { padding: 28px; }
  .hero-copy h1 { font-size: clamp(53px, 9.1vw, 95px); }
  .hero-art { min-height: 300px; }
  .mode { min-height: 94px; }
  .mode-content span { font-size: 0.72rem; }
}

@media (max-width: 650px) {
  :root { --page-gutter: 10px; }
  .header-inner { min-height: 56px; gap: 12px; }
  .brand-mark { width: 36px; height: 36px; font-size: 20px; }
  .brand-name { font-size: 11px; }
  .brand { gap: 6px; }
  .player-badge { padding-block: 3px; padding-inline-start: 4px; }
  .player-badge img { width: 34px; height: 34px; }
  .page { padding-block: 10px max(24px, calc(var(--safe-bottom) + 12px)); }
  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(100px, 0.7fr);
    min-height: 184px;
    border-radius: var(--radius);
  }
  .hero-copy { padding: 16px 0 16px 14px; }
  .hero-copy h1 { font-size: clamp(30px, 9.6vw, 62px); }
  .hero-copy p { max-width: 13em; margin-top: 12px; line-height: 1.5; font-size: 0.81rem; }
  .hero-art { min-height: 0; overflow: visible; }
  .hero-stage { width: 116%; min-height: 0; height: 100%; margin-inline-start: -12%; }
  .hero-platform { border-width: 2px; box-shadow: 0 4px 0 #1c3c32; }
  .hero-piece-one { width: 46%; left: 13%; }
  .hero-piece-two { width: 43%; left: 38%; }
  .hero-piece-three { width: 42%; left: 20%; }
  .mode-list { grid-template-columns: 1fr; gap: 8px; margin-top: 12px; }
  #home .mode { min-height: 74px; padding: 8px 14px 8px 10px; }
  .mode-versus { padding: 7px 9px; }
  .versus-choice .mode-symbol { width: 36px; }
  .mode-symbol { width: 51px; }
  .mode-content { gap: 3px; }
  .mode-content strong { font-size: 1rem; }
  .mode-content span { font-size: 0.76rem; }
  .play-layout { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .board-column { gap: 6px; }
  .play-heading { min-height: 44px; margin-bottom: 6px; }
  .board { border-radius: 13px; }
  .board-heading {
    position: relative;
    inset: auto;
    min-height: 36px;
    padding: 3px 9px;
    border-bottom: 1px solid #b9cdb5;
  }
  #board-status, #turn-clock { min-height: auto; padding: 3px 8px; }
  #board-status { border-color: transparent; background: none; padding-inline: 1px; }
  #board-canvas {
    /* 盤面の縦横比を保ちながら、手番表示と操作の高さを差し引く。 */
    --board-space: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 280px);
    width: min(100%, clamp(132px, calc(var(--board-space) * 0.75), 485px));
  }
  .board-overlay { padding: 10px; }
  .board-message { padding: 16px 12px; }
  .game-side { gap: 8px; }
  .control-panel { padding: 7px 8px; border-radius: 12px; }
  .control-panel { display: grid; gap: 6px; }
  .stats { margin: 0; gap: 5px; }
  .stats > div { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 3px; }
  .stats > div:not(:first-child) { border-inline-start: 1px solid var(--line); padding-inline-start: 5px; }
  .stats strong { font-size: 1.21rem; }
  #next-piece { width: 25px; height: 25px; }
  .controls { gap: 4px; }
  .controls [data-adjust] { flex-basis: 44px; }
  .controls .primary-button { min-width: 46px; padding-inline: 3px; font-size: 0.8rem; }
  .play-error { margin-top: 0; }
  .keyboard-guide { margin-top: 9px; }

  #profile-dialog { --dialog-bottom: max(44px, calc(var(--safe-bottom) + 32px)); }
  #profile-heading { font-size: 1.18rem; }
  .profile-edit-footer { justify-content: stretch; }
  #profile-dialog input, #profile-dialog select { font-size: 1rem; }
  #profile-dialog .icon-picker { grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }
  #profile-dialog .title-inputs select { font-size: 0.875rem; }
  #save-profile { width: 100%; }
}

@media (pointer: coarse) { .keyboard-guide { display: none; } }
@media (max-width: 360px) {
  .controls { flex-wrap: wrap; }
  #pose-toggle { flex-basis: 100%; justify-content: center; }
}

@media (max-width: 650px) and (max-height: 600px) {
  #board-canvas {
    --board-space: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 312px);
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  body:has(#play:not([hidden])) .header-inner { min-height: 56px; }
  .page:has(#play:not([hidden])) { padding-block-start: 10px; }
  .play-heading { min-height: 44px; margin: 0 0 6px; }
  .board-stage { container-type: inline-size; }
  .board-heading { position: absolute; inset: 6px 8px auto; border: 0; padding: 0; min-height: 0; }
  #board-status { border-color: #b9cdb5; background: #f3f8ec; padding: 3px 8px; }
  #board-canvas {
    --board-space: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 174px);
    width: min(100%, clamp(110px, calc(var(--board-space) * 0.75), 485px));
  }
  .board-overlay { padding: 6px; }
  .board-message { padding: 7px 12px; }
  .board-message h2 { margin-bottom: 4px; line-height: 1.2; }
  .board-message p { margin-bottom: 6px; line-height: 1.4; }
  @container (min-width: 526px) {
    .picker-sheet:has(#pose-picker:not([hidden])) { width: 510px; }
    #pose-picker { grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }
  }
}

@media (orientation: landscape) and (max-width: 650px) and (max-height: 540px) {
  .play-layout:has(#game-stats:not([hidden])) { grid-template-columns: minmax(0, 1fr) minmax(150px, 32%); }
  .stats { display: grid; }
  .stats > div:not(:first-child) { border-inline-start: 0; padding-inline-start: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mode { transition: none; }
  .emote-effect { animation-timing-function: steps(1, end); }
  .emote-effect[data-effect] > span { animation: none; }
}
