*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1923;
  --surface: #1a2736;
  --surface2: #223344;
  --border: #2a3a4d;
  --text: #e8edf2;
  --text2: #a0b0c0;
  --accent: #f0c040;
  --energy: #5ce85c;
  --star: #e8d040;
  --hp-player: #40c840;
  --hp-enemy: #e04040;
  --hp-companion: #b060e0;
  --danger: #e05050;
  --block: #5090d0;
  --card-attack: #c43030;
  --card-skill: #3080d0;
  --card-power: #d0a030;
  --card-status: #606060;
}

html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ─── Compact global nav override ─── */
.siteNav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 6px 10px 4px;
}
.siteNav .siteBrand {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-bottom: 4px;
}
.siteNav .siteBrandParent {
  font-size: 9px;
  color: var(--text2);
  display: block;
  line-height: 1;
}
.siteNav .siteBrandName {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.siteNav .siteNavLinks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.siteNav .siteNavLink {
  text-align: center;
  padding: 5px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface2);
}
.siteNav .siteNavLink:active { background: var(--border); }
.siteNav .siteNavLink.isCurrent {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(240, 192, 64, 0.1);
}


/* ─── App shell ─── */
.simApp {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.phase { flex: 1; display: flex; flex-direction: column; position: relative; }
#setupPhase { overflow-y: auto; overflow-x: hidden; }
#combatPhase { overflow: hidden; }

/* ─── Setup ─── */
.setupPanel { max-width: 480px; width: 100%; margin: 0 auto; padding: 16px 16px; }
.setupNav {
  display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; font-size: 12px;
}
.setupNav a {
  color: var(--text); text-decoration: none;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface2);
}
.setupNav a:active { background: var(--border); }
.setupTitle { font-size: 18px; font-weight: 700; margin-bottom: 20px; text-align: center; }
.setupNotice {
  margin-top: 16px; padding: 12px; font-size: 11px; line-height: 1.5;
  color: var(--text2); background: var(--surface); border-radius: 6px;
  border: 1px solid var(--border);
}
.setupNotice p { margin-bottom: 6px; }
.setupNotice p:last-child { margin-bottom: 0; }
.setupNotice a { color: var(--accent); text-decoration: none; }
.setupVersion { font-size: 10px; opacity: 0.8; }
.setupDisclaimer {
  margin-top: 12px; font-size: 10px; color: var(--text2); text-align: center; line-height: 1.5;
}
.setupDisclaimer a { color: var(--accent); text-decoration: none; }
.setupFields { display: flex; flex-direction: column; gap: 12px; }
.setupRow { display: flex; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.fieldHalf { flex: 1; }
.fieldLabel { font-size: 12px; font-weight: 600; }
.fieldInput {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
}
.fieldInput:focus { border-color: var(--accent); }
select.fieldInput { cursor: pointer; }
.btnPrimary {
  display: block; width: 100%; margin-top: 20px; padding: 12px;
  background: var(--accent); color: #000; font-size: 15px; font-weight: 700;
  border: none; border-radius: 8px; cursor: pointer;
}
.btnPrimary:active { opacity: 0.85; }
.btnPrimary:disabled { opacity: 0.4; cursor: default; }
.btnGhost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 8px 16px; border-radius: 6px; font-size: 14px; cursor: pointer;
}
.btnGhost:active { background: var(--surface2); }

/* ─── Context bar ─── */
.contextBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.contextRelics {
  display: flex; gap: 3px; align-items: center;
  flex: 1; min-width: 0; overflow-x: auto;
  scrollbar-width: none;
}
.contextRelics::-webkit-scrollbar { display: none; }
.contextRelicIcon {
  width: 24px; height: 24px; border-radius: 3px; flex-shrink: 0; cursor: default;
}
.contextBtn {
  width: 28px; height: 28px;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text2); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.contextBtn:active { background: var(--surface2); }
.settingsBox { text-align: left; }
.settingsBox .btnPrimary { margin-top: 12px; }

/* ─── Relic editor modal ─── */
.relicEditorBox { text-align: left; max-width: 400px; width: 95vw; max-height: 80vh; display: flex; flex-direction: column; padding: 0; }
.relicEditorBox .editorModalHead { padding: 10px 12px; }
.relicEditorBody { flex: 1; overflow-y: auto; padding: 0 12px; }
.relicEditorBox .editorModalFoot { padding: 8px 12px; }
.relicCurrentList { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; min-height: 28px; }
.relicCurrentItem {
  display: flex; align-items: center; gap: 3px;
  padding: 2px 6px; background: var(--surface2); border-radius: 4px;
  font-size: 11px; cursor: pointer;
}
.relicCurrentItem img { width: 20px; height: 20px; border-radius: 3px; }
.relicCurrentItem:hover { background: var(--danger); }
.relicCurrentItem::after { content: '✕'; font-size: 9px; color: var(--text2); margin-left: 2px; }
.relicSearchWrap { margin-bottom: 6px; }
.relicSearchWrap input { width: 100%; font-size: 13px; padding: 6px 8px; }
.relicSearchResults { display: flex; flex-direction: column; gap: 2px; }
.relicSearchItem {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
.relicSearchItem:hover { background: var(--surface2); }
.relicSearchItem img { width: 24px; height: 24px; border-radius: 3px; }
.relicSearchItem.alreadyOwned { opacity: 0.4; }

/* ─── Deck editor modal ─── */
.editorModal {
  width: 95vw; height: 90vh; max-width: 600px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
}
.editorModalHead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.editorFrame {
  flex: 1; border: none; width: 125%; background: var(--bg);
  transform: scale(0.8); transform-origin: top left; height: 125%;
}
.editorModalFoot {
  padding: 6px 12px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.editorNote { font-size: 11px; color: var(--text2); text-align: center; }

/* ─── Battle stage ─── */
.stage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  gap: 8px;
  background: linear-gradient(180deg, #0d2218 0%, #0f1923 40%, #1a1525 100%);
  flex-shrink: 0;
}
.actor { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.enemySide { justify-content: flex-end; }
.actorIcon {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface2); border: 2px solid var(--border);
  flex-shrink: 0; overflow: hidden;
}
.actorIcon img, .avatarImg { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatarFallback { width: 100%; height: 100%; background: var(--surface); border-radius: 50%; }
.actorInfo { flex: 1; min-width: 0; }
.actorInfoEnemy { text-align: right; }

.hpRow { display: flex; align-items: center; gap: 6px; }
.enemySide .hpRow { flex-direction: row-reverse; }
.hpBar { flex: 1; height: 12px; background: #1a1a2e; border-radius: 3px; overflow: hidden; border: 1px solid #333; }
.hpFill { height: 100%; border-radius: 2px; transition: width 0.3s ease; }
.playerFill { background: var(--hp-player); }
.enemyFill { background: var(--hp-enemy); float: right; }
.hpText { font-size: 11px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.enemySide .hpText { text-align: right; }

.statRow { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; font-size: 11px; max-height: 40px; overflow: hidden; }
.enemySide .statRow { justify-content: flex-end; }
.statChip { padding: 1px 5px; border-radius: 3px; white-space: nowrap; font-weight: 600; }
.statChip.isBuff { background: rgba(92, 232, 92, 0.15); color: var(--energy); }
.statChip.isDebuff { background: rgba(224, 80, 80, 0.15); color: var(--danger); }
.statChip.isBlock { background: rgba(80, 144, 208, 0.2); color: var(--block); }
.powerIcon { width: 16px; height: 16px; vertical-align: middle; margin-right: 1px; border-radius: 2px; }
.statusRow .powerIcon { width: 18px; height: 18px; margin-right: 4px; }

.stageCenter {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 36px;
}
.stageTurn { font-size: 10px; font-weight: 700; color: var(--text2); }
.stageResources { display: flex; align-items: center; gap: 6px; }
.stageEnergy {
  display: flex; align-items: center; gap: 1px;
  font-size: clamp(11px, 14px, 14px); font-weight: 700;
  max-width: 48px;
}
.stageEnergy img { width: 16px; height: 16px; }
.stageStar {
  display: flex; align-items: center; gap: 1px;
  font-size: 14px; font-weight: 700; color: var(--star);
}
.stageStar img { width: 16px; height: 16px; }

.intentRow { margin-top: 3px; font-size: 11px; font-weight: 600; }
.companionRow { margin-top: 4px; font-size: 11px; }
.companionHp {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 6px; background: var(--surface2); border-radius: 3px;
  border-left: 2px solid var(--hp-companion); font-size: 10px;
}

/* ─── Pending ─── */
.pendingBar {
  padding: 5px 12px; background: var(--surface2);
  border-top: 1px solid var(--accent); font-size: 12px;
  font-weight: 600; text-align: center; color: var(--accent);
  flex-shrink: 0;
}

/* ─── Card detail ─── */
.cardDetail {
  padding: 5px 12px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  height: 72px;
}
.cardDetailInner { display: flex; flex-direction: column; gap: 2px; }
.cardDetailHead { display: flex; align-items: center; gap: 6px; }
.cardDetailName { font-weight: 700; font-size: 13px; }
.cardDetailCost {
  display: inline-flex; align-items: center; gap: 1px;
  font-size: 12px; font-weight: 700;
}
.cardDetailCost img { width: 13px; height: 13px; vertical-align: middle; }
.cardDetailType { font-size: 11px; color: var(--text2); }
.btnPlay {
  margin-left: auto; padding: 2px 12px;
  background: var(--accent); color: #000; font-weight: 700; font-size: 11px;
  border: none; border-radius: 4px; cursor: pointer; flex-shrink: 0;
}
.btnPlay:disabled { opacity: 0.4; cursor: default; }
.btnPlay:active:not(:disabled) { opacity: 0.85; }
.cardDetailDesc { font-size: 12px; line-height: 1.4; }

/* ─── Hand ─── */
.handDock {
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.handScroll { overflow: hidden; }
.handRail {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  padding: 4px 4px;
  min-height: 130px;
}
.handCard {
  min-width: 0; padding: 2px 3px 3px;
  background: var(--surface2); border: 2px solid transparent;
  border-radius: 5px; cursor: pointer; text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative; user-select: none; -webkit-user-select: none;
}
.handCard.selected { border-color: var(--accent); box-shadow: 0 0 8px 2px rgba(240, 192, 64, 0.5); }
.handCard.isAttack { border-bottom: 2px solid var(--card-attack); }
.handCard.isSkill { border-bottom: 2px solid var(--card-skill); }
.handCard.isPower { border-bottom: 2px solid var(--card-power); }
.handCard.isStatus { border-bottom: 2px solid var(--card-status); }
.handCardCost {
  position: absolute; top: 2px; left: 2px;
  font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,0.7); padding: 0 4px; border-radius: 3px;
}
.handCardName {
  font-size: 10px; font-weight: 600; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.handCardImg {
  width: 100%; height: 32px; object-fit: cover;
  border-radius: 3px; margin-top: 1px; pointer-events: none;
}

/* ─── Pile strip ─── */
.pileStrip {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 3px 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.pileStrip span { white-space: nowrap; }

/* ─── Card detail flash ─── */
@keyframes cardDetailFlashAnim {
  0% { background-color: rgba(240, 192, 64, 0.35); }
  100% { background-color: var(--surface2); }
}
.cardDetail.cardDetailFlash {
  animation: cardDetailFlashAnim 200ms ease-out;
}
@keyframes cardDetailShakeAnim {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.cardDetail.cardDetailShake {
  animation: cardDetailShakeAnim 300ms ease-out;
  border-color: var(--danger);
}

/* ─── Action bar (T終了 + 最初から + 戻す) ─── */
.actionBar {
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.actionBtn {
  flex: 1;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.actionBtn:disabled { opacity: 0.35; cursor: default; }
.actionBtn:active:not(:disabled) { filter: brightness(0.85); }
.actionBtnEnd {
  background: var(--accent);
  color: #000;
  flex: 2;
}
.actionBtnReset {
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
}
.actionBtnReset:active:not(:disabled) { background: var(--danger); color: #fff; }
.actionBtnUndo {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ─── Overlay ─── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.confirmBox, .outcomeBox {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; text-align: center;
  max-width: 320px; width: 90%;
}
.confirmActions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.outcomeBox { font-size: 20px; font-weight: 700; }
.outcomeBox .btnPrimary { margin-top: 16px; }

/* ─── Info panel ─── */
.infoPanel {
  flex: 1; min-height: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  position: relative;
}
.infoPanel::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0; height: 24px;
  background: linear-gradient(transparent, var(--surface));
  pointer-events: none;
}
.infoTabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.infoTab {
  flex: 1; padding: 6px; background: none; border: none;
  color: var(--text2); font-size: 12px; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent;
}
.infoTab.active { color: var(--accent); border-bottom-color: var(--accent); }
.infoTab:active { background: var(--surface2); }
.infoBody { flex: 1; overflow-y: auto; padding: 6px 10px 56px; font-size: 12px; }
.moveItem { padding: 4px 6px; border-radius: 4px; margin-bottom: 3px; }
.moveItem.isActive { background: var(--surface2); border-left: 3px solid var(--accent); }
.moveLabel { font-weight: 600; }
.moveDesc { font-size: 11px; }
.pileGrid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.pileSectionTitle { font-weight: 700; margin-bottom: 3px; font-size: 11px; }
.pileCard { font-size: 11px; padding: 1px 0; border-bottom: 1px solid var(--border); }
.logItem { font-size: 11px; padding: 2px 0; border-bottom: 1px solid var(--border); }
.emptyLabel { color: var(--text2); font-style: italic; }
.deckRelicRow { display: flex; align-items: center; gap: 4px; padding: 2px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.deckEditBtns { display: flex; gap: 8px; margin-top: 8px; }
.deckEditBtns .actionBtn { flex: 1; }
.deckRelicIcon { width: 20px; height: 20px; border-radius: 3px; }
.statusSection { margin-bottom: 8px; }
.statusRow { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.statusKey { font-weight: 600; }
.statusVal { font-weight: 700; }


/* ─── Ad slot ─── */
.adSlot {
  flex-shrink: 0; height: 50px;
  background: var(--surface); border-top: 1px solid var(--border);
}

/* ─── Responsive ─── */
@media (min-width: 640px) {
  .stage { padding: 16px 32px; }
  .actorIcon { width: 64px; height: 64px; }
  .handRail { min-height: 72px; }
  .handCardImg { height: 44px; }
  .handCardName { font-size: 11px; }
}

/* ─── AdSense side-rail clearance (PC only) ─── */
@media (min-width: 1200px) {
  body { padding-left: 160px; padding-right: 160px; }
}
