:root {
  --bg: #111827;
  --panel: #f8fafc;
  --panel-strong: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.13);
  --accent: #f59e0b;
  --good: #10b981;
  --bad: #e11d48;
  --blue: #2563eb;
  --shadow: 0 18px 44px rgba(2, 6, 23, 0.24);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Noto Sans JP",
    sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 480px);
  display: flex;
  height: 100vh;
  height: 100svh;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  overflow: hidden;
  padding: calc(8px + var(--safe-top)) 10px calc(8px + var(--safe-bottom));
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.18rem, 5vw, 1.72rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.05rem;
}

.icon-button,
.direction-button,
.primary-button,
.secondary-button,
.share-button,
.ranking-tab {
  min-height: 44px;
  border-radius: 8px;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

.icon-button:active,
.direction-button:active,
.primary-button:active,
.secondary-button:active,
.share-button:active,
.ranking-tab:active {
  transform: translateY(1px) scale(0.99);
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.icon-button[aria-pressed="true"] {
  background: var(--good);
}

.score-strip {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
  margin: 8px 0 6px;
}

.score-strip div,
.name-row,
.result-name-row,
.ranking-panel,
.status-row,
.public-note {
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.score-strip div {
  min-width: 0;
  padding: 5px 4px;
  border-radius: 8px;
}

.score-strip span {
  display: block;
  color: var(--muted);
  font-size: clamp(0.5rem, 2.05vw, 0.62rem);
  font-weight: 800;
  text-transform: uppercase;
}

.score-strip strong {
  display: block;
  min-height: 1.08rem;
  color: var(--ink);
  font-size: clamp(0.72rem, 2.8vw, 0.98rem);
  line-height: 1.2;
  white-space: nowrap;
}

.name-row {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
}

.result-name-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px;
  border-radius: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

#playerName {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

#playerName:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.primary-button,
.secondary-button,
.share-button {
  padding: 0 16px;
  font-weight: 900;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

.name-row .primary-button,
.status-row .secondary-button {
  min-height: 38px;
  padding: 0 10px;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.share-button {
  display: grid;
  grid-column: 1 / -1;
  min-height: 44px;
  place-items: center;
  border: 1px solid #020617;
  background: #020617;
  color: #ffffff;
}

.instagram-share-button {
  border-color: #c13584;
  background: linear-gradient(135deg, #f58529 0%, #dd2a7b 44%, #8134af 100%);
}

.share-button[aria-disabled="true"],
.instagram-share-button:disabled {
  pointer-events: none;
  opacity: 0.45;
}

.error-text {
  flex: 0 0 auto;
  grid-column: 1 / -1;
  min-height: 14px;
  margin: 2px 2px 5px;
  color: var(--bad);
  font-size: 0.78rem;
  font-weight: 800;
}

.game-board {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.fall-area {
  position: relative;
  flex: 1 1 auto;
  height: auto;
  min-height: 170px;
  overflow: hidden;
  border: 2px solid rgba(15, 23, 42, 0.86);
  border-radius: 8px;
  background:
    linear-gradient(rgba(15, 23, 42, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.06) 1px, transparent 1px),
    #ffffff;
  background-size: 28px 28px, 28px 28px, auto;
  box-shadow: var(--shadow);
  outline: none;
  touch-action: none;
}

.fall-area:focus {
  box-shadow:
    var(--shadow),
    0 0 0 4px rgba(37, 99, 235, 0.22);
}

.speed-lane {
  position: absolute;
  z-index: 0;
  inset: 0 33% 0 33%;
  border-inline: 1px solid rgba(15, 23, 42, 0.1);
  background: rgba(15, 23, 42, 0.025);
}

.timing-target {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(21% - 43px);
  width: 86px;
  height: 86px;
  border: 3px solid rgba(2, 6, 23, 0.22);
  border-radius: 50%;
  background: rgba(2, 6, 23, 0.035);
  box-shadow:
    inset 0 0 0 12px rgba(2, 6, 23, 0.025),
    0 0 0 1px rgba(255, 255, 255, 0.72);
  pointer-events: none;
  transform: translateX(-50%);
}

.timing-target::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(2, 6, 23, 0.3);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  content: "";
  transform: translate(-50%, -50%);
}

.judge-line {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 21%;
  left: 0;
  height: 6px;
  background: #000000;
  box-shadow:
    0 2px 0 rgba(15, 23, 42, 0.24),
    0 0 0 1px rgba(255, 255, 255, 0.5);
}

.judge-line::before {
  position: absolute;
  top: -18px;
  left: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 2px solid #020617;
  background: #ffffff;
  color: #020617;
  content: "ココ ▶︎";
  font-size: 0.72rem;
  font-weight: 950;
}

.piece-layer {
  position: absolute;
  z-index: 3;
  inset: 0;
}

.fall-piece {
  position: absolute;
  top: 0;
  left: 50%;
  display: grid;
  width: var(--size);
  height: var(--size);
  place-items: center;
  color: #020617;
  filter: drop-shadow(0 16px 12px rgba(0, 0, 0, 0.32));
  transform-origin: center center;
  transform: translate(-50%, -50%);
  will-change: transform;
}

.fall-piece.target {
  color: #020617;
  filter:
    drop-shadow(0 0 12px rgba(37, 99, 235, 0.28))
    drop-shadow(0 16px 12px rgba(0, 0, 0, 0.3));
}

.fall-piece.giant,
.fall-piece.sway-giant {
  z-index: 2;
}

.fall-piece .motif {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.fall-piece .sprite-motif {
  transform-origin: center center;
}

.fall-piece .shadow-dot {
  position: absolute;
  z-index: -1;
  width: 56%;
  height: 18%;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.45);
  transform: translateY(145%);
  filter: blur(3px);
}

.center-message {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  display: grid;
  width: min(74%, 290px);
  min-height: 118px;
  place-items: center;
  padding: 18px;
  border: 1px solid rgba(248, 250, 252, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.83);
  color: #fff;
  cursor: pointer;
  text-align: center;
  transform: translate(-50%, -50%);
}

.center-message:focus-visible {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.38);
  outline: none;
}

body.fever-mode {
  background:
    repeating-linear-gradient(180deg, #020617 0 16px, #111827 16px 32px),
    #020617;
}

body.fever-mode .app-shell {
  background:
    repeating-linear-gradient(180deg, rgba(245, 158, 11, 0.18) 0 10px, transparent 10px 22px),
    linear-gradient(180deg, #fff7ed 0%, #dbeafe 48%, #fef3c7 100%);
  animation: fever-shell 360ms steps(2, end) infinite;
}

body.fever-mode .score-strip div,
body.fever-mode .status-row,
body.fever-mode .public-note,
body.fever-mode .ranking-panel {
  border-color: rgba(2, 6, 23, 0.45);
  background: rgba(255, 255, 255, 0.94);
  box-shadow:
    0 0 0 2px rgba(245, 158, 11, 0.4),
    0 12px 24px rgba(225, 29, 72, 0.18);
}

body.fever-mode #feverValue,
body.fever-mode #statusText {
  color: #e11d48;
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.45);
}

.fall-area.fever {
  border-color: #000000;
  background:
    repeating-linear-gradient(180deg, rgba(245, 158, 11, 0.16) 0 14px, rgba(37, 99, 235, 0.11) 14px 28px, rgba(225, 29, 72, 0.11) 28px 42px),
    linear-gradient(rgba(15, 23, 42, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.06) 1px, transparent 1px),
    #ffffff;
  background-size: auto, 28px 28px, 28px 28px, auto;
  box-shadow:
    var(--shadow),
    0 0 0 5px rgba(245, 158, 11, 0.8),
    0 0 0 10px rgba(225, 29, 72, 0.32),
    0 0 34px rgba(37, 99, 235, 0.42),
    inset 0 0 56px rgba(245, 158, 11, 0.28);
  animation: festival-board 260ms steps(2, end) infinite;
}

.fall-area.fever::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  background:
    repeating-linear-gradient(180deg, transparent 0 12px, rgba(2, 6, 23, 0.08) 12px 14px, transparent 14px 26px),
    repeating-linear-gradient(180deg, transparent 0 18px, rgba(245, 158, 11, 0.2) 18px 22px, transparent 22px 42px),
    linear-gradient(180deg, rgba(225, 29, 72, 0.16), rgba(37, 99, 235, 0.12), rgba(16, 185, 129, 0.12));
  content: "";
  mix-blend-mode: multiply;
  opacity: 1;
  pointer-events: none;
  animation: festival-confetti 480ms linear infinite;
}

.fall-area.fever .timing-target {
  border-color: rgba(225, 29, 72, 0.82);
  background: rgba(245, 158, 11, 0.18);
  box-shadow:
    inset 0 0 0 12px rgba(255, 255, 255, 0.35),
    0 0 0 4px rgba(245, 158, 11, 0.7),
    0 0 26px rgba(225, 29, 72, 0.62);
  animation: target-pulse 360ms ease-in-out infinite;
}

.fall-area.fever .judge-line {
  height: 8px;
  background: #000;
  box-shadow:
    0 0 0 2px #ffffff,
    0 0 18px rgba(245, 158, 11, 0.9),
    0 0 34px rgba(225, 29, 72, 0.62);
}

.fall-area.fever .judge-line::before {
  background: #facc15;
  color: #020617;
  box-shadow: 0 0 16px rgba(225, 29, 72, 0.55);
}

.fall-area.fever .fall-piece.target {
  filter:
    drop-shadow(0 0 22px rgba(250, 204, 21, 0.92))
    drop-shadow(0 0 15px rgba(225, 29, 72, 0.72))
    drop-shadow(0 16px 12px rgba(0, 0, 0, 0.3));
}

.fall-area.fever .fall-piece {
  animation: fever-piece 300ms ease-in-out infinite;
}

.fall-area[data-sfx="just"] .timing-target,
.fall-area[data-sfx="fever"] .timing-target {
  animation: target-burst 220ms ease-out;
}

.center-message[hidden] {
  display: none;
}

.center-message strong {
  font-size: 1.65rem;
  line-height: 1;
}

.center-message span {
  color: #cbd5e1;
  font-size: 0.92rem;
  font-weight: 800;
}

.control-pad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, 1fr);
  width: min(100%, clamp(156px, 27svh, 222px));
  gap: 8px;
  flex: 0 0 auto;
  margin: 8px auto;
}

.direction-button {
  display: grid;
  width: 100%;
  min-height: 0;
  aspect-ratio: 1 / 1;
  place-items: center;
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: #fff;
  color: var(--ink);
  font-size: clamp(1rem, 4.4vw, 1.28rem);
  font-weight: 950;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.1);
}

.direction-button.up {
  grid-area: up;
}

.direction-button.left {
  grid-area: left;
}

.direction-button.right {
  grid-area: right;
}

.direction-button.down {
  grid-area: down;
}

.direction-button.flash-good {
  background: var(--good);
  color: #fff;
}

.direction-button.flash-bad {
  background: var(--bad);
  color: #fff;
}

.status-row {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  padding: 6px;
  border-radius: 8px;
}

#statusText {
  color: var(--muted);
  font-size: clamp(0.7rem, 2.9vw, 0.82rem);
  font-weight: 800;
}

.public-note {
  flex: 0 0 auto;
  margin: 0;
  padding: 5px 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: clamp(0.58rem, 2.5vw, 0.68rem);
  font-weight: 800;
  line-height: 1.25;
}

.ranking-panel {
  flex: 0 0 auto;
  margin: 0 0 7px;
  padding: 5px;
  border-radius: 8px;
}

.ranking-toggle {
  display: flex;
  width: 100%;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 950;
}

.ranking-toggle::after {
  color: var(--muted);
  content: "開く";
  font-size: 0.72rem;
  font-weight: 900;
}

.ranking-toggle[aria-expanded="true"]::after {
  content: "閉じる";
}

#bestScoreText {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.ranking-body {
  padding: 6px;
}

.ranking-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 2px 0 8px;
}

.ranking-tab {
  min-height: 32px;
  padding: 0 4px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: clamp(0.62rem, 2.7vw, 0.76rem);
  font-weight: 900;
}

.ranking-tab.active {
  background: var(--blue);
  color: #fff;
}

.ranking-list {
  display: grid;
  gap: 6px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.ranking-list .rank {
  color: var(--accent);
  font-weight: 950;
}

.ranking-list .name {
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-list .meta {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.ranking-list .points {
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

.empty-rank {
  display: flex !important;
  align-items: center !important;
  grid-template-columns: none !important;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.72);
}

.modal-backdrop[hidden] {
  display: none;
}

.result-modal {
  width: min(100%, 360px);
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.38);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.result-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.result-grid dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-grid dd {
  margin: 2px 0 0;
  font-size: 1.28rem;
  font-weight: 950;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (min-width: 760px) {
  body {
    background: linear-gradient(135deg, #0f172a 0%, #111827 46%, #1f2937 100%);
  }

  .app-shell {
    height: auto;
    margin-block: 18px;
    overflow: visible;
    border-radius: 16px;
    min-height: calc(100vh - 36px);
  }
}

@media (max-height: 720px) {
  .eyebrow {
    display: none;
  }

  .score-strip {
    margin: 6px 0 5px;
  }

  .score-strip div {
    padding-block: 4px;
  }

  .error-text {
    min-height: 12px;
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  .fall-area {
    min-height: 150px;
  }

  .center-message {
    min-height: 96px;
    padding: 14px;
  }

  .center-message strong {
    font-size: 1.34rem;
  }

  .control-pad {
    width: min(100%, clamp(144px, 25svh, 198px));
    gap: 6px;
    margin-block: 6px;
  }

  .status-row {
    margin-bottom: 5px;
    padding-block: 5px;
  }

  .public-note {
    padding-block: 4px;
  }
}

@keyframes festival-board {
  0% {
    transform: translateX(0);
  }

  25% {
    transform: translate(1px, -1px) rotate(-0.15deg);
  }

  50% {
    transform: translate(-1px, 1px) rotate(0.15deg);
  }

  75% {
    transform: translate(1px, 1px) rotate(-0.1deg);
  }

  100% {
    transform: translateX(0);
  }
}

@keyframes festival-confetti {
  from {
    background-position: 0 0, 0 0, 0 0;
  }

  to {
    background-position: 0 44px, 0 84px, 0 0;
  }
}

@keyframes fever-shell {
  0%,
  100% {
    filter: saturate(1.15) brightness(1);
  }

  50% {
    filter: saturate(1.45) brightness(1.06);
  }
}

@keyframes target-pulse {
  0%,
  100% {
    transform: translateX(-50%) scale(1);
  }

  50% {
    transform: translateX(-50%) scale(1.12);
  }
}

@keyframes target-burst {
  0% {
    transform: translateX(-50%) scale(0.88);
  }

  45% {
    transform: translateX(-50%) scale(1.34);
  }

  100% {
    transform: translateX(-50%) scale(1);
  }
}

@keyframes fever-piece {
  0%,
  100% {
    filter:
      drop-shadow(0 0 16px rgba(250, 204, 21, 0.7))
      drop-shadow(0 16px 12px rgba(0, 0, 0, 0.3));
  }

  50% {
    filter:
      drop-shadow(0 0 26px rgba(225, 29, 72, 0.82))
      drop-shadow(0 0 16px rgba(37, 99, 235, 0.62))
      drop-shadow(0 16px 12px rgba(0, 0, 0, 0.3));
  }
}

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