html,
body {
  /* height: 100%; */
}

body,
body * {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* カラーテーマ変数 */
:root {
  --bg: #f7f7fb;
  --top-panel: #ffffffc9;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --brand: #ffe069;
  --accent: #10b981;
  --danger: #ef4444;
  --ring: #60a5fa55;

  --bg-color: var(--bg);
  --text-color: var(--text);
  --popup-bg: var(--panel);
  --playerbo-bg: var(--brand);
  --hp-bg: #e2e8f0;
  --negative-bg: var(--danger);
  --positive-bg: var(--accent);
  --positive-color: #061018;
  --overlay-bg: rgba(0, 0, 0, 0.5);
  --neutral-bg: #303a57;
}

html.dark-mode {
  --bg: #0b1020;
  --top-panel: #121933c9;
  --panel: #121933c9;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --brand: #d4a017;
  --accent: #10b981;
  --danger: #ef4444;
  --ring: #60a5fa55;

  --bg-color: var(--bg);
  --text-color: var(--text);
  --popup-bg: var(--panel);
  --playerbo-bg: var(--brand);
  --hp-bg: #1e293b;
  --negative-bg: var(--danger);
  --positive-bg: var(--accent);
  --positive-color: #061018;
  --overlay-bg: rgba(0, 0, 0, 0.8);
  --neutral-bg: #303a57;
}

body {
  margin: 0;
  height: 85vh;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2648 0%, var(--bg) 50%), var(--bg);
  color: var(--text-color);
}

#app {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  }
/* 
.stage {
  min-height: 100dvh;
} */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 20px;
}

#timer {
  font-size: 24px;
  font-weight: bold;
  color: var(--text-color);
  cursor: pointer;
  background: var(--top-panel);
  padding: 2px 8px;
}

#boCounter {
  width: 130px;
  text-align: center;
  font-size: 30px;
  font-weight: bold;
  color: var(--text-color);
  cursor: pointer;
  background: var(--top-panel);
  border: 1px solid #24305a;
  border-radius: 8px;
  padding: 2px 8px;
}

.icon-button {
  background: none;
  border: none;
  font-size: 32px;
  cursor: pointer;
}

.icon-button.purple {
  background: purple;
  color: white;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  display: flex;
  flex: 1;
  width: 100%;
  height: 100dvh;
}

.side.player {
  width: 35%;
  height: 80dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
}

.hp {
  background: var(--hp-bg);
  color: var(--text-color);
  width: 100%;
  margin: 25px 0;
  font-size: 40px;
  font-weight: bold;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--muted);
  border-radius: 8px;
}

.wins {
    background: var(--playerbo-bg);
    width: 90px;
    padding: 8px;
    margin-bottom: 25px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    border: 0.5px solid var(--muted);
    border-radius: 8px;
    cursor: pointer;
}

.player-name {
  margin: 5px 0;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  cursor: pointer;
}

.rotate-left {
  transform: rotate(-90deg);
}

.rotate-right {
  transform: rotate(90deg);
}

.center {
  width: 30%;
  /* height: 80dvh; */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
  box-sizing: border-box;
  overflow: hidden;
}

.negative,
.positive {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  /* height: 100%; */
}

.select-value {
  width: 90%;
  margin: 3px 0px;
  padding: 20px 0;
  font-size: 26px;
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 8px;
  transition: transform 0.1s, box-shadow 0.1s;
}

.negative .select-value {
  background: var(--negative-bg);
}

.positive .select-value {
  background: var(--positive-bg);
  color: var(--positive-color);
}

.select-value.selected {
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.negative .select-value.selected {
  background: linear-gradient(45deg, #ff9d9d, #ff4d4d);
}

.positive .select-value.selected {
  background: linear-gradient(45deg, #8fff9f, #32cc4b);
  color: #000;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.overlay.show {
  display: flex;
}

#winnerOverlay .popup {
  background: linear-gradient(135deg, #fff8dc, #ffd700);
  border: 4px solid #ffd700;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.6),
              0 0 40px rgba(255, 215, 0, 0.4);
  animation: winnerPopup 0.4s ease-out;
  text-align: center;
}

#winnerOverlay #winnerMessage {
  color: #b8860b;
  text-shadow: 0 0 10px #fff, 0 0 20px #ffd700;
}

@keyframes winnerPopup {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

#winnerOverlay.show {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#winnerOverlay .tap-to-close {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #fff;
  opacity: 0.8;
}

.popup {
  background: var(--popup-bg);
  color: var(--text-color);
  padding: 20px;
  border-radius: 8px;
  width: 80%;
  max-width: 300px;
  box-sizing: border-box;
}

.popup-buttons {
  margin-top: 10px;
  text-align: right;
}

.popup>label,
button,
select {
  font-size: 20px;
}

/* ダークモード切り替えスイッチ */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--neutral-bg);
  transition: 0.4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: 0.4s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--playerbo-bg);
}

.switch input:checked + .slider:before {
  transform: translateX(26px);
}

/* ポップアップ内のボタンデザイン */
.overlay button {
  width: 100%;
  margin: 5px 0;
  padding: 10px 0;
  border: none;
  border-radius: 8px;
  background: var(--playerbo-bg);
  color: #000;
  cursor: pointer;
}


.overlay button.close-button {
  background: var(--neutral-bg);
  color: #fff;
}

.overlay button:hover {
  opacity: 0.9;
}

#saveHp {
  background: var(--accent);
  color: var(--positive-color);
}

#applyHp {
  background: var(--brand);
  color: var(--positive-color);
}

#clearHp {
  background: var(--danger);
  color: #fff;
}

#resetData {
  background: var(--negative-bg);
  color: #fff;
}

#guideOverlay {
  pointer-events: none;
}

#guidePopup {
  display: none;
  position: fixed;
  z-index: 2000;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

#guidePopup.show {
  display: block;
}

#guideOverlay .popup {
  pointer-events: auto;
}

.guide-highlight {
  position: relative;
  z-index: 1001;
  box-shadow: 0 0 10px 4px yellow;
}

/* タブレット向けレイアウト */
@media (min-width: 601px) and (max-width: 1024px) {
  .side.player {
    width: 30%;
  }

  .center {
    width: 40%;
    padding: 20px 0;
  }

  .icon-button {
    font-size: 32px;
  }

  .hp {
    width: 80%;
  }

  #timer,
  #boCounter {
    font-size: 32px;
  }

  .select-value {
    font-size: 32px;
    padding: 20px 0;
    width: 80%;
  }
}

/* PC向けレイアウト */
@media (min-width: 1025px) {
  body {
    height: 100vh;
  }
  
  #app {
    max-width: 1000px;
    margin: 0 auto;
  }

  .top-bar {
    width: 70%;
  }

  .side.player {
    width: 25%;
  }

  .center {
    width: 50%;
    padding: 20px 0;
  }

  .hp {
    max-width: 65%;
  }

  .icon-button {
    font-size: 36px;
  }

  #timer,
  #boCounter {
    font-size: 36px;
  }

  .select-value {
    width: 70%;
    font-size: 36px;
    padding: 25px 0;
  }
}

@media (max-width: 600px) {
  .side.player {
    width: 35%;
  }

  .center {
    width: 30%;
    padding: 10px 0;
  }

  .icon-button {
    font-size: 28px;
  }
}

/* 小さい画面向けレイアウト */
@media (max-width: 375px) {
  .select-value {
    margin: 5px 2%;
    padding: 15px 0;
    font-size: 20px;
  }

}

/* JSで .pwa-mode が付いた場合のスタイル */
.pwa-mode body {
  margin-top: 20px;
  padding-top: env(safe-area-inset-top);
  /* ノッチ対応 */
  padding-bottom: env(safe-area-inset-bottom);
}

.pwa-mode .top-bar {
  margin-bottom: 25px;
}

/* 要素に data-hide-mode="pwa" が指定された場合、PWAモードでは非表示 */
.pwa-mode [data-hide-mode~="pwa"] {
  display: none !important;
}
