:root {
  --bg: #f2f2f0;
  --bg-2: #d9d9d5;
  --accent: #111111;
  --accent-2: #333333;
  --primary: #c8c8c4;
  --primary-strong: #111111;
  --text: #111111;
  --text-soft: #61615d;
  --card: #ffffff;
  --danger: #111111;
  --shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
  --radius: 18px;
  --home-control-height: 96px;
  --home-control-gap: 8px;
  --home-control-bottom: calc(var(--home-control-gap) + var(--viewport-bottom) - var(--pwa-top-compensation));
  --home-control-top: calc(100dvh - var(--viewport-bottom) - var(--home-control-height) - var(--home-control-gap));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --visual-bottom: 0px;
  --keyboard-bottom: 0px;
  --viewport-bottom: 0px;
  --pwa-top-compensation: 0px;
}

@media (display-mode: standalone) {
  :root {
    --pwa-top-compensation: var(--safe-top);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

html {
  background: var(--bg-2);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  background:
    radial-gradient(circle at 15% 0%, #ffffff 0, transparent 36%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

.app {
  position: fixed;
  top: 0;
  right: 0;
  bottom: calc(0px - var(--safe-bottom) - var(--pwa-top-compensation));
  left: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: auto;
  min-height: 0;
  overflow: visible;
  padding: calc(8px + var(--safe-top)) 12px calc(8px + var(--safe-bottom));
  background:
    radial-gradient(circle at 15% 0%, #ffffff 0, transparent 36%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  gap: 10px;
}

.app-header {
  position: relative;
  min-height: 126px;
  margin: -8px -12px 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  flex: 0 0 auto;
  background: #111111;
  border-bottom: 1px solid #000000;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}
.brand-lockup {
  position: relative;
  z-index: 2;
  min-width: 220px;
  padding: 12px 24px 11px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 16px;
  background: rgba(10,10,10,.82);
  box-shadow: 0 8px 24px rgba(0,0,0,.36);
  backdrop-filter: blur(4px);
}
.app-header h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 2px;
  color: #ffffff;
}
.app-header h1::after {
  content: "";
  display: block;
  width: 48px;
  height: 4px;
  margin: 4px auto 0;
  background: #ffffff;
  border-radius: 2px;
}
.subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: #cfcfcb;
}
.icon-marquee {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  opacity: .42;
  transform: rotate(-2deg) scale(1.04);
}
.icon-marquee::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.65), transparent 24%, transparent 76%, rgba(0,0,0,.65));
}
.icon-marquee-row {
  display: flex;
  width: max-content;
  gap: 7px;
  animation: marquee-left 38s linear infinite;
  will-change: transform;
}
.icon-marquee-row-reverse {
  margin-left: -46px;
  animation-name: marquee-right;
  animation-duration: 44s;
}
.icon-marquee-row img {
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  border-radius: 11px;
  object-fit: cover;
  filter: grayscale(1) contrast(1.08);
  box-shadow: 4px 5px 0 rgba(255,255,255,.16);
}
@keyframes marquee-left {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@keyframes marquee-right {
  from { transform: translateX(-50%); }
  to { transform: translateX(0); }
}

.section-title {
  font-size: 14px;
  margin: 0 4px 6px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.count {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  background: #111111;
  color: #ffffff;
  border-radius: 11px;
  font-size: 12px;
  text-align: center;
  font-weight: 700;
}

.mode-switch {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 3px;
  border: 1px solid #c8c8c4;
  border-radius: 15px;
  background: rgba(255,255,255,.58);
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.mode-button {
  min-width: 0;
  min-height: 52px;
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  cursor: pointer;
}
.mode-button[aria-selected="true"] {
  border-color: #000000;
  background: #111111;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0,0,0,.22);
}
.mode-button:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: -5px;
}
.mode-button-title,
.mode-button-note {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mode-button-title {
  font-size: 14px;
  font-weight: 800;
}
.mode-button-note {
  margin-top: 1px;
  font-size: 9px;
  opacity: .72;
}
.mode-panel {
  flex: 1 1 auto;
  min-height: 0;
}
.mode-panel.is-active {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#single-mode-panel.is-active {
  padding-bottom: calc(var(--home-control-height) + var(--home-control-gap));
}
#multi-mode-panel.is-active {
  padding-bottom: calc(var(--home-control-height) + var(--home-control-gap));
}
.mode-panel[hidden] {
  display: none;
}

.games-section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.games-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding: 4px;
  align-content: start;
}
.game-card {
  min-width: 0;
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid #d0d0cc;
  box-shadow: var(--shadow);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
  aspect-ratio: 1 / 1;
  transition: transform .08s ease, box-shadow .08s ease;
}
.game-card:active {
  transform: scale(0.97);
  box-shadow: 0 3px 8px rgba(0,0,0,.16);
}
.game-card img {
  width: 68%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #f7f7f4;
  border-radius: 14px;
  box-shadow: 7px 8px 12px rgba(0,0,0,.2);
}
.game-card .game-name {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: #000000;
}
.game-card .game-min {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-soft);
  text-align: center;
}
.game-card.empty {
  background: rgba(255,255,255,0.5);
  border: 2px dashed rgba(10,37,64,0.2);
  color: var(--text-soft);
  font-size: 12px;
  aspect-ratio: 1 / 1;
}

.players-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.34);
  backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity .2s ease;
}
.players-backdrop[hidden] {
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}
.players-section {
  z-index: 50;
  max-height: var(--home-control-height);
  display: flex;
  flex-direction: column;
  padding: 0 12px;
  overflow: hidden;
  transition:
    top .24s cubic-bezier(.2,.75,.25,1),
    left .24s cubic-bezier(.2,.75,.25,1),
    right .24s cubic-bezier(.2,.75,.25,1),
    bottom .24s cubic-bezier(.2,.75,.25,1),
    height .24s cubic-bezier(.2,.75,.25,1),
    max-height .24s cubic-bezier(.2,.75,.25,1),
    border-radius .24s ease;
  will-change: height;
}
.players-section.is-open {
  top: auto;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: calc(70dvh + var(--visual-bottom));
  max-height: calc(70dvh + var(--visual-bottom));
  padding-bottom: calc(var(--safe-bottom) + var(--visual-bottom));
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 28px rgba(0,0,0,.22);
}
.players-toggle {
  flex: 0 0 var(--home-control-height);
  width: 100%;
  min-height: var(--home-control-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5px 0 8px;
  border: 0;
  background: transparent;
  color: #111111;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.players-toggle strong {
  display: inline-grid;
  min-width: 25px;
  height: 25px;
  margin: 0 3px;
  place-items: center;
  border-radius: 999px;
  background: #111111;
  color: #ffffff;
  font-size: 12px;
}
.players-toggle-icon {
  position: relative;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  transition: transform .2s ease;
}
.players-toggle-icon::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 10px;
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 12px solid #111111;
}
.players-section.is-open .players-toggle-icon {
  transform: rotate(180deg);
}
.players-sheet-content {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: 10px;
  overflow: hidden;
}
.player-form {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.player-input {
  min-width: 0;
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 2px solid #b8b8b4;
  border-radius: 10px;
  background: #ffffff;
  font-size: 15px;
  color: var(--text);
  outline: none;
}
.player-input:focus { border-color: var(--primary-strong); }
.btn-add {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 14px;
  background: #111111;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
}
.btn-add:active { background: #3a3a3a; }

.players-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.players-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #ffffff;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid #ddddda;
  box-shadow: 0 2px 5px rgba(0,0,0,.08);
}
.player-name {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-remove {
  background: transparent;
  border: none;
  font-size: 18px;
  color: #111111;
  cursor: pointer;
  padding: 4px 8px;
  font-weight: 700;
}
.empty-list {
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
  padding: 12px 0;
}

@media (prefers-reduced-motion: reduce) {
  .players-section,
  .players-backdrop {
    transition: none;
  }
}

.multi-empty {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px;
  border: 1px solid #c8c8c4;
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(255,255,255,.86), rgba(255,255,255,.86)),
    repeating-linear-gradient(-45deg, #eeeeeb 0, #eeeeeb 8px, #dadad6 8px, #dadad6 9px);
  box-shadow: var(--shadow);
  text-align: center;
}
.multi-empty-icon {
  position: relative;
  width: 118px;
  height: 76px;
  margin-bottom: 18px;
}
.multi-empty-icon span {
  position: absolute;
  bottom: 0;
  width: 45px;
  height: 72px;
  border: 4px solid #111111;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 7px 8px 0 #c6c6c2;
}
.multi-empty-icon span::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #111111;
  transform: translateX(-50%);
}
.multi-empty-icon span:nth-child(1) { left: 0; transform: rotate(-8deg); }
.multi-empty-icon span:nth-child(2) { left: 37px; z-index: 1; }
.multi-empty-icon span:nth-child(3) { right: 0; transform: rotate(8deg); }
.multi-empty-label {
  margin: 0 0 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-soft);
}
.multi-empty h2 {
  margin: 0;
  font-size: 23px;
}
.multi-empty > p:not(.multi-empty-label) {
  max-width: 310px;
  margin: 10px 0 18px;
  color: var(--text-soft);
  font-size: 13px;
}
.multi-empty-status {
  padding: 7px 18px;
  border: 1px solid #111111;
  border-radius: 999px;
  background: #111111;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.home-control-card {
  position: fixed;
  top: var(--home-control-top);
  left: 12px;
  right: 12px;
  bottom: auto;
  width: auto;
  height: var(--home-control-height);
  min-height: var(--home-control-height);
  border: 1px solid #c8c8c4;
  border-radius: var(--radius);
  background: rgba(248,248,246,.98);
  box-shadow: var(--shadow);
}

.multi-profile {
  z-index: 2;
  padding: 12px;
  transform: translateY(calc(-1 * var(--keyboard-bottom)));
  transition: transform .2s ease;
}
.multi-profile label {
  display: block;
  margin: 0 2px 7px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}
.multi-username-input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 2px solid #b8b8b4;
  border-radius: 11px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.multi-username-input:focus {
  border-color: #111111;
  box-shadow: 0 0 0 3px rgba(17,17,17,.12);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .icon-marquee-row,
  .multi-profile {
    animation-play-state: paused;
    transition: none;
  }
}
