/* ねらいうちゲーム - 水タイプ青系スタイル */

:root {
  --bg: #f0f9ff;
  --btn-primary: #38bdf8;
  --btn-primary-hover: #0ea5e9;
  --btn-secondary: #bae6fd;
  --btn-secondary-hover: #7dd3fc;
  --btn-pressed: #0284c7;
  --text: #0c4a6e;
  --text-muted: #0369a1;
  --placeholder: #7dd3fc;
  --border: #bae6fd;
  --danger: #dc2626;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 14px rgba(2, 132, 199, 0.15);
  --banner-h: 3.25rem;
  --banner-h-duel: 4.85rem;
  --result-h: 5.5rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
}

.screen {
  display: none;
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* ========== スタート画面 ========== */
#screen-start,
#screen-setup {
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(125, 211, 252, 0.55), transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 30%, rgba(186, 230, 253, 0.45), transparent 55%),
    linear-gradient(180deg, #e0f2fe 0%, var(--bg) 38%, #f8fbff 100%);
}

#screen-start {
  display: none;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

#screen-start.active {
  display: block;
}

.app-version-wrap {
  position: absolute;
  top: max(0.6rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  max-width: calc(100% - 1.5rem);
  pointer-events: none;
  user-select: none;
  z-index: 2;
}

.app-version-wrap .app-version {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.app-version-wrap .app-release-notes {
  white-space: pre-line;
  font-size: 0.65rem;
}

.start-scroll {
  width: 100%;
}

.start-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: calc(100dvh - 4.5rem);
  padding:
    max(3.5rem, calc(env(safe-area-inset-top) + 2.5rem))
    1.25rem
    0.75rem;
  text-align: center;
}

.start-hero::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3rem;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(240, 249, 255, 0.92));
}

.start-rules-invite {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1.75rem;
  padding: 0 0 0.25rem;
  text-align: center;
}

.start-rules-players {
  margin: 0;
  font-size: clamp(0.88rem, 3.2vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.start-rules-label {
  margin: 0;
  font-family: "Zen Maru Gothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  font-size: clamp(1.25rem, 4.8vw, 1.55rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.start-scroll-cue {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  color: var(--text-muted);
  text-decoration: none;
  animation: start-cue-bounce 1.6s ease-in-out infinite;
  touch-action: manipulation;
}

.start-scroll-chevron {
  display: block;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

@keyframes start-cue-bounce {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.75;
  }
  50% {
    transform: translateY(6px);
    opacity: 1;
  }
}

.app-title {
  margin: 0 0 1.1rem;
  font-family: "Zen Maru Gothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  font-size: clamp(2rem, 8vw, 2.75rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--text);
  text-align: center;
  animation: start-rise 0.7s ease-out both;
}

.start-hero-icon {
  width: min(42vw, 168px);
  height: min(42vw, 168px);
  margin: 0 0 1.5rem;
  object-fit: contain;
  border-radius: 28%;
  box-shadow: 0 10px 28px rgba(2, 132, 199, 0.18);
  animation: start-rise 0.7s ease-out 0.08s both, start-float 4.5s ease-in-out 0.9s infinite;
}

.start-hero .btn-start-large {
  animation: start-rise 0.7s ease-out 0.16s both;
}

@keyframes start-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes start-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.start-rules {
  width: min(92vw, 520px);
  margin: -0.5rem auto 0;
  padding: 0.75rem 0 max(2.5rem, env(safe-area-inset-bottom));
  scroll-margin-top: 1rem;
  text-align: left;
}

.rule-phase {
  padding: 0.25rem 0 0.5rem;
  animation: start-rise 0.75s ease-out both;
}

.rule-phase--filter {
  animation-delay: 0.22s;
}

.rule-phase--snipe {
  animation-delay: 0.32s;
}

.rule-phase-head {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.rule-phase-num {
  font-family: "Zen Maru Gothic", "Hiragino Sans", sans-serif;
  font-size: clamp(1.6rem, 6vw, 2rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--btn-primary);
}

.rule-phase--snipe .rule-phase-num {
  color: var(--danger);
}

.rule-phase-title {
  margin: 0;
  font-family: "Zen Maru Gothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  font-size: clamp(1.35rem, 5.2vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text);
  line-height: 1.25;
}

.rule-phase-lead {
  margin: 0 0 0.85rem;
  font-size: clamp(0.98rem, 3.6vw, 1.12rem);
  line-height: 1.75;
  color: var(--text);
}

.rule-goal-em {
  font-size: 1.08em;
  font-weight: 900;
  color: var(--btn-pressed);
  letter-spacing: 0.02em;
}

.rule-lineage-note {
  margin: 0 0 0.85rem;
  padding: 0.75rem 0.85rem;
  font-size: clamp(0.9rem, 3.2vw, 1rem);
  line-height: 1.65;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  border-left: 3px solid var(--btn-primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.rule-phase-sub {
  margin: 0.9rem 0 0.45rem;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-muted);
}

.rule-phase-figure {
  margin: 0.85rem 0 1.1rem;
  padding: 0;
}

.rule-phase-figure img {
  display: block;
  width: 100%;
  height: auto;
  background: transparent;
  mix-blend-mode: screen;
}

.rule-list {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
  font-size: clamp(0.92rem, 3.3vw, 1.02rem);
  line-height: 1.7;
  color: var(--text);
}

.rule-list li {
  margin-bottom: 0.35rem;
}

.rule-list--warn {
  margin-bottom: 0;
}

.rule-dobon {
  margin: 1rem 0 0.25rem;
  padding: 0.85rem 0 0.85rem 0.9rem;
  border-left: 3px solid var(--danger);
}

.rule-dobon-title {
  margin: 0 0 0.45rem;
  font-size: clamp(0.92rem, 3.3vw, 1.02rem);
  font-weight: 700;
  line-height: 1.55;
  color: var(--danger);
}

.rule-phase-connector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.4rem 0 1.6rem;
  color: var(--text-muted);
}

.rule-phase-connector-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.rule-phase-connector-label {
  flex: 0 0 auto;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.start-rules .rules-help-hint {
  margin: 1.75rem 0 0;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-muted);
  text-align: left;
}

.start-contact {
  margin: 1rem 0 0;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-muted);
  text-align: left;
}

.start-contact a {
  color: var(--btn-pressed);
  text-decoration: none;
}

.start-contact a:hover {
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .app-title,
  .start-hero-icon,
  .start-hero .btn-start-large,
  .start-scroll-cue,
  .rule-phase {
    animation: none;
  }
}

/* オーバーレイ内ルール（ヘルプ等） */
.rules-box-overlay {
  margin: 0;
  width: auto;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: none;
  border-radius: 0;
  box-shadow: none;
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--text-muted);
  /* 左右・下の読みやすさ用余白（ヘッダとは別） */
  padding: 0.85rem 1.15rem 1.5rem;
}

.rules-overlay-inner {
  max-width: min(92vw, 440px);
}

.rules-box-overlay p {
  margin: 0 0 0.65rem;
}

.rules-box-overlay ul {
  margin: 0.5rem 0 0.75rem;
  padding-left: 1.35rem;
}

.rules-box-overlay li {
  margin-bottom: 0.35rem;
}

.rules-box-overlay .rules-detail {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.btn-primary {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: bold;
  border-radius: var(--radius);
  border: none;
  background: var(--btn-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.2s, transform 0.1s;
  touch-action: manipulation;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-start-large {
  width: min(90vw, 280px);
  padding: 1.1rem 2rem;
  font-size: clamp(1.05rem, 4vw, 1.25rem);
}

/* ========== ルール選択 ========== */
#screen-setup {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.setup-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(2rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
  width: 100%;
}

.setup-title {
  margin: 0 0 1.5rem;
  font-size: 1.35rem;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(92vw, 340px);
  margin-bottom: 2rem;
}

.mode-standard-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.mode-standard-wrap .btn-mode-standard {
  flex: 1;
  min-width: 0;
}

/* ルール選択ボタンと紛らわしくない、おまけ程度の小さなヘルプ印（主ボタンの右） */
.btn-standard-help {
  flex-shrink: 0;
  box-sizing: border-box;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid #7dd3fc;
  background: rgba(255, 255, 255, 0.55);
  color: var(--text-muted);
  opacity: 0.75;
  cursor: help;
  touch-action: manipulation;
  box-shadow: none;
}

.btn-standard-help:hover,
.btn-standard-help:focus-visible {
  opacity: 1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  outline: none;
}

.btn-mode {
  width: 100%;
  padding: 1.1rem 1rem;
  font-size: 1.1rem;
  font-weight: bold;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: none;
  touch-action: manipulation;
  background: #c8ecfd;
  color: var(--text-muted);
}

.btn-mode:hover {
  background: #bde8fd;
  color: var(--text);
}

.btn-mode.pressed {
  background: var(--btn-pressed);
  color: #fff;
  border: none;
  transform: scale(0.97);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.22);
}

.btn-mode.pressed:hover {
  background: var(--btn-pressed);
}

.mode-gen-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.select-generation,
.select-time {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  max-width: 100%;
}

.select-generation:disabled {
  background: #ececec;
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.72;
}

.time-select-wrap {
  width: min(92vw, 340px);
  margin-bottom: 1.25rem;
}

.random-first-wrap {
  width: min(92vw, 340px);
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.random-first-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.random-first-buttons {
  display: flex;
  gap: 0.5rem;
}

.random-first-buttons .btn-mode {
  flex: 1;
  padding: 0.85rem 0.5rem;
  font-size: 1rem;
}

.time-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.btn-back-setup {
  position: absolute;
  top: max(0.6rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  z-index: 1;
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--btn-secondary);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.btn-back-setup:hover {
  background: var(--btn-secondary-hover);
}

.setup-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(92vw, 340px);
}

.btn-start-setup {
  flex: 1;
  max-width: 220px;
  padding: 0.85rem 1.5rem;
  font-size: 1.1rem;
  font-weight: bold;
  border-radius: var(--radius);
  border: none;
  background: var(--btn-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
  transition: background 0.2s, transform 0.1s;
}

.btn-start-setup:hover {
  background: var(--btn-primary-hover);
}

.btn-start-setup:active {
  transform: scale(0.98);
}

/* ========== ゲーム画面 3ゾーン ========== */
#screen-game {
  display: none;
  flex-direction: column;
}

#screen-game.active {
  display: flex;
}

#screen-game.screen-shake {
  animation: screen-shake 0.35s ease-in-out;
}

@keyframes screen-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-10px); }
  30% { transform: translateX(10px); }
  45% { transform: translateX(-8px); }
  60% { transform: translateX(8px); }
  75% { transform: translateX(-4px); }
  90% { transform: translateX(4px); }
}

.banner-zone {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem max(0.5rem, env(safe-area-inset-left)) 0.35rem max(0.5rem, env(safe-area-inset-right));
  padding-top: max(0.35rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  min-height: var(--banner-h);
}

.banner-zone.banner-zone--duel {
  min-height: var(--banner-h-duel);
  align-items: center;
}

.btn-banner {
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-banner:hover {
  background: var(--btn-secondary);
}

.banner-actions-left {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.btn-cheat {
  color: var(--text-muted);
  font-size: 0.62rem;
}

.btn-cheat:hover {
  color: var(--text);
  background: var(--btn-secondary);
}

.btn-cheat.active {
  color: var(--text);
  background: var(--btn-secondary);
  border-color: var(--btn-primary);
  box-shadow: inset 0 2px 5px rgba(2, 132, 199, 0.2);
}

.btn-cheat.cheat-used {
  color: var(--text);
  background: #d9effc;
  border-color: #9dd4f5;
}

.banner-center {
  text-align: center;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

.banner-title-row[hidden],
.banner-duel-row[hidden],
#btn-reveal[hidden],
#btn-cancel-duel[hidden] {
  display: none !important;
}

.banner-title-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  max-width: 100%;
}

.banner-title {
  margin: 0;
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-rules-help {
  flex-shrink: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.62rem;
  font-weight: normal;
  line-height: 1.2;
  border-radius: var(--radius-sm);
  border: 1px solid #f5b8b8;
  background: #fde8e8;
  color: #b91c1c;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-rules-help:hover {
  background: #fcd4d4;
  color: #991b1b;
  border-color: #f0a0a0;
}

.banner-actions-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.banner-duel-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.banner-timer {
  margin: 0;
  font-size: clamp(1.1rem, 5vw, 1.4rem);
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.btn-cancel-duel {
  flex-shrink: 0;
  padding: 0.25rem 0.55rem;
  font-size: 0.68rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--btn-secondary);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-cancel-duel:hover {
  background: var(--btn-secondary-hover);
}

.banner-timer.timer-urgent {
  color: var(--danger);
}

.main-zone {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
  padding: 0.5rem max(0.35rem, env(safe-area-inset-left)) 0.5rem max(0.35rem, env(safe-area-inset-right));
}

.conditions-wrap {
  width: 100%;
  max-width: 100%;
}

.conditions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  table-layout: fixed;
}

.conditions-table th,
.conditions-table td {
  padding: 0.35rem 0.2rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

.conditions-table th {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: normal;
  text-align: center;
}

.col-no { width: 1.6rem; text-align: center; }
.col-kind { width: 18%; }
.col-value { width: 32%; }
.col-op { width: 26%; }
.col-actions { width: 4.4rem; }

.cell-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

tr.condition-excluded td {
  background: rgba(91, 113, 124, 0.72);
  color: var(--text);
}

tr.condition-excluded .btn-del,
tr.condition-excluded .btn-exclude,
tr.condition-excluded .select-kind,
tr.condition-excluded .select-stat,
tr.condition-excluded .input-stat,
tr.condition-excluded .select-efficacy,
tr.condition-excluded .btn-op {
  background: #b3b3b3;
  border-color: rgba(70, 88, 97, 0.85);
}

tr.condition-excluded .btn-exclude.active {
  background: #b3b3b3;
  color: var(--text);
  border-color: var(--btn-primary);
}

tr.condition-excluded .btn-pick {
  background: #82a1b1;
  border-color: rgba(70, 88, 97, 0.85);
}

tr.condition-excluded .btn-pick.picked {
  background: #b3b3b3;
}

tr.condition-excluded .btn-op.active {
  background: #015f96;
  color: #fff;
  border-color: #015f96;
}

.btn-exclude {
  padding: 0.22rem 0.35rem;
  font-size: 0.65rem;
  line-height: 1.2;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-exclude.active {
  background: #fff;
  color: var(--text);
  border-color: var(--btn-primary);
  font-weight: bold;
}

.btn-del {
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.select-kind {
  width: 100%;
  min-width: 0;
  padding: 0.3rem 0.15rem;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.btn-pick {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.4rem;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--btn-secondary);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}

.btn-pick.picked {
  background: #fff;
}

.type-icon-sm {
  width: 20px;
  height: 20px;
  object-fit: contain;
  flex-shrink: 0;
}

.stat-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.select-stat,
.input-stat {
  width: 100%;
  min-width: 0;
  padding: 0.3rem;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.select-efficacy {
  width: 100%;
  min-width: 5.5rem;
  padding: 0.3rem;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.op-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.btn-op {
  padding: 0.3rem 0.2rem;
  font-size: 0.68rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
}

.btn-op.active {
  background: var(--btn-primary);
  color: #fff;
  border-color: var(--btn-primary);
}

.cell-placeholder {
  color: var(--placeholder);
  font-size: 0.75rem;
}

.btn-add-condition {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.6rem;
  font-size: 0.85rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

/* ========== 結果ゾーン ========== */
.result-zone {
  flex: 0 0 auto;
  padding: 0.6rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  min-height: var(--result-h);
}

.result-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.dobon-stack {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  margin-left: 0.5rem;
  max-width: 38%;
}

.dobon-stack[hidden] {
  display: none !important;
}

.dobon-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
}

.dobon-image {
  display: block;
  width: min(28vw, 96px);
  height: auto;
}

.dobon-note {
  margin: 0;
  font-size: 0.58rem;
  line-height: 1.35;
  color: var(--text-muted);
  max-width: 7.5rem;
}

.dobon-image.dobon-slam {
  animation: dobon-slam 0.35s ease-out;
}

@keyframes dobon-slam {
  0% {
    transform: scale(1.5);
    opacity: 0.3;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.result-stats-block {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: 100%;
}

.result-stats-block[hidden] {
  display: none !important;
}

.result-summary {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 0.2rem;
  row-gap: 0.05rem;
  text-align: center;
}

.result-heading {
  grid-row: 1 / 3;
  grid-column: 1;
  align-self: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-right: 0.15rem;
  white-space: nowrap;
}

.result-stat-row {
  display: contents;
}

.result-stat-row--count .result-count,
.result-stat-row--count .result-label {
  grid-row: 1;
}

.result-stat-row--count .result-count {
  grid-column: 2;
}

.result-stat-row--count .result-label {
  grid-column: 3;
}

.result-stat-row--lines .result-lines,
.result-stat-row--lines .result-label {
  grid-row: 2;
}

.result-stat-row--lines .result-lines {
  grid-column: 2;
}

.result-stat-row--lines .result-label {
  grid-column: 3;
}

.result-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.result-count {
  font-size: clamp(1.6rem, 7vw, 2.2rem);
  font-weight: bold;
  color: var(--danger);
  margin: 0;
  line-height: 1.1;
}

.result-lines {
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  font-weight: bold;
  color: var(--text);
  margin: 0;
  line-height: 1.1;
}

.result-legend {
  flex: 0 1 auto;
  text-align: left;
  min-width: 0;
  max-width: 42%;
}

.result-legend-line {
  margin: 0.1rem 0;
  font-size: 0.62rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.result-legend-key {
  font-weight: bold;
  color: var(--text);
}

.result-zone:has(#result-answer-wrap:not([hidden])) {
  min-height: 9.5rem;
  padding-top: 0.85rem;
}

.result-answer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  max-width: 100%;
}

.result-answer-wrap[hidden] {
  display: none !important;
}

.result-answer {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  margin: 0;
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.btn-share-x {
  align-self: flex-end;
  flex-shrink: 0;
  margin: 0 0 0.35rem;
  padding: 0.37rem 0.85rem;
  font-size: 0.6rem;
  font-weight: bold;
  border: none;
  border-radius: var(--radius-sm);
  background: #000;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-share-x[hidden] {
  display: none !important;
}

.btn-share-x:hover {
  background: #222;
}

.answer-line {
  margin: 0.35rem 0;
  font-size: clamp(0.9rem, 4vw, 1.1rem);
  font-weight: bold;
  text-align: center;
  line-height: 1.4;
  word-break: break-word;
}

.answer-line .form-suffix {
  font-size: 0.82em;
  font-weight: bold;
}

.btn-reveal {
  margin-top: 0.5rem;
  padding: 0.55rem 1.25rem;
  font-size: 0.9rem;
  font-weight: bold;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--btn-pressed);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

/* ========== ローディング ========== */
#screen-loading {
  align-items: center;
  justify-content: center;
}

.loading-text {
  color: var(--text-muted);
}

/* ========== ダイアログ ========== */
.dialog {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.dialog.active {
  display: flex;
}

.dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.dialog-box {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  max-width: min(90vw, 340px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.dialog-message {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.btn-dialog {
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  font-weight: bold;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
}

.btn-dialog-yes {
  background: var(--btn-primary);
  color: #fff;
  border-color: var(--btn-primary);
}

.btn-dialog-no {
  background: #fff;
  color: var(--text);
}

/* ========== オーバーレイ共通 ========== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 0.75rem 4rem;
  padding-top: max(2rem, env(safe-area-inset-top));
  background: rgba(0, 0, 0, 0.4);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* 検索: キーボード表示時は JS が visualViewport に合わせて top/height を上書き */
#overlay-search {
  overscroll-behavior: contain;
}

#overlay-search .overlay-inner {
  max-height: min(70vh, 70dvh);
}

.overlay.active {
  display: flex;
}

.overlay-inner {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  max-height: min(80vh, 80dvh);
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.overlay-title {
  margin: 0;
  font-size: 1rem;
}

.btn-close-overlay {
  flex-shrink: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--btn-secondary);
  cursor: pointer;
  touch-action: manipulation;
}

/* タイプ選択 */
.type-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  padding: 0.75rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.type-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  touch-action: manipulation;
}

.type-btn img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
}

.type-btn:hover {
  background: var(--btn-secondary);
}

/* 検索 */
.search-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-header input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem;
  min-height: 0;
}

.search-result-item {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.25rem;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  touch-action: manipulation;
}

.search-result-item:hover {
  background: var(--btn-secondary);
}

.search-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 1rem;
  margin: 0;
}

.type-btn:not(:has(img)) {
  justify-content: center;
}

/* ねらいうちモードポップアップ */
.overlay-duel {
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  overflow: visible;
  padding: 0;
}

.duel-popup {
  position: relative;
  background: transparent;
  border-radius: 0;
  padding: 0 1.25rem 1.25rem;
  width: min(88vw, 300px);
  text-align: center;
  box-shadow: none;
  margin-top: 3rem;
}

#overlay-duel .duel-popup.screen-shake {
  animation: screen-shake 0.35s ease-in-out;
}

.duel-image {
  display: block;
  width: min(70vw, 220px);
  height: auto;
  margin: -4.5rem auto 0.75rem;
  position: relative;
  z-index: 1;
}

.duel-timer {
  display: inline-block;
  margin: 0;
  padding: 0.7rem 1.7rem;
  min-width: min(36vw, 140px);
  font-size: clamp(3rem, 14vw, 4rem);
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
}

@media (min-width: 400px) {
  .op-toggle {
    flex-direction: row;
  }

  .btn-op {
    flex: 1;
  }

  .stat-inputs {
    flex-direction: row;
    align-items: stretch;
  }

  .stat-inputs .btn-pick {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .select-stat {
    flex: 1;
  }

  .select-efficacy {
    flex: 0 0 5.5rem;
    width: auto;
  }

  .input-stat {
    flex: 0 0 4rem;
  }
}
