/* スマホ縦画面向けレイアウト */
:root {
  --card-base-w: 180;
  --card-base-h: 300;
  --card-scale: 1;
  --header-h: 52px;
  --footer-h: 64px;
  --order-bar-h: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #f4f5f7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #222;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
}

.app-header {
  flex: 0 0 var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid #ddd;
  background: #fff;
  z-index: 10;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lang-select {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #444;
}

.lang-select-label {
  white-space: nowrap;
}

.lang-select select {
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 5px 6px;
  font-size: 12px;
  background: #fff;
  max-width: 118px;
}

.app-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.btn-icon {
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mode-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.mode-tabs::-webkit-scrollbar {
  display: none;
}

.mode-tab {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #ccc;
  background: #fff;
  color: #333;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.mode-tab.active {
  background: #222;
  border-color: #222;
  color: #fff;
}

.app-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  padding: 8px 12px 0;
  /* 下部固定バー（順番操作 + フッター）分の余白 */
  padding-bottom: calc(var(--order-bar-h) + var(--footer-h) + var(--safe-bottom) + 8px);
}

/* 活用ボード表示時は答えエリアが重ならないよう左余白を確保 */
.app-main.has-board .answer-bar {
  padding-left: 112px;
}

.app-main.has-board .answer-text {
  align-self: stretch;
  text-align: center;
}

/* カード表示エリア（はみ出しはここだけに閉じ込める） */
.play-area {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.answer-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 1.8em;
  text-align: center;
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 600;
  margin-bottom: 4px;
  width: 100%;
  z-index: 3;
}

.answer-always {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  color: #444;
  margin: 0;
}

.answer-text {
  display: inline-block;
  background: rgba(255, 255, 255, 0.95);
  padding: 2px 8px;
  border-radius: 6px;
}

.answer-text.hidden {
  visibility: hidden;
}

.answer-text.visible {
  visibility: visible;
}

.board-panel {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  z-index: 5;
  max-width: 108px;
}

.board-panel.visible {
  display: block;
}

.board-sprite {
  width: 100px;
  height: 70px;
  border: 1px solid #ccc;
  box-shadow: 2px 2px 2px #ddd;
  background-repeat: no-repeat;
  background-size: 100px auto;
}

.board-badges {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
}

.badge {
  display: inline-block;
  color: #fff;
  border-radius: 4px;
  padding: 1px 6px;
  margin: 1px 0;
}

.card-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

#cardbox {
  /* transform 後の見た目サイズ分をレイアウト上も確保する */
  width: calc(var(--card-base-w) * 1px * var(--card-scale));
  height: calc(var(--card-base-h) * 1px * var(--card-scale));
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}

.card-face,
.card-back {
  display: block;
  width: calc(var(--card-base-w) * 1px * var(--card-scale));
  height: calc(var(--card-base-h) * 1px * var(--card-scale));
  border-radius: 16px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.card-face {
  background-color: #ddd;
}

.order-row {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--footer-h) + var(--safe-bottom));
  z-index: 19;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  width: 100%;
  max-width: 480px;
  height: var(--order-bar-h);
  margin: 0;
  padding: 0 12px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid #ddd;
}

.app-footer {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid #ddd;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.btn {
  border: 1px solid #333;
  background: #fff;
  color: #222;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  min-width: 72px;
}

.btn-primary {
  background: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}

.btn.active {
  background: #222;
  color: #fff;
}

.footer-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
  display: none;
}

.settings-panel.open {
  display: block;
}

.settings-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 12px 16px calc(16px + var(--safe-bottom));
}

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.settings-head h2 {
  margin: 0;
  font-size: 16px;
}

.form-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.form-list li {
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

.form-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
}

#carddata {
  display: none;
}

/* 旧スプライト（180x300 基準）— スケールは JS が表示領域に合わせて設定 */
#cardbox .legacy-card {
  width: 180px !important;
  height: 300px !important;
  background-size: 1080px 30000px !important;
  border-radius: 16px !important;
  transform: scale(var(--card-scale));
  transform-origin: center center;
  flex-shrink: 0;
}
