@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;700;900&display=swap');

:root {
  --bg:      #0f1923;
  --surface: #1a2535;
  --card:    #212f45;
  --border:  #2e4060;
  --accent:  #f7c948;
  --correct: #4cde7b;
  --wrong:   #ff5c6e;
  --text:    #e8f0fe;
  --muted:   #7a91b0;
  --header-h: 54px;
  --info-h:   32px;
}

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

body {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ══════════════════════════════
   メイン画面レイアウト
══════════════════════════════ */
#mainView {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── ヘッダー ── */
#appHeader {
  flex-shrink: 0;
  min-height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
#appHeader::-webkit-scrollbar { display: none; }

#appTitle {
  font-size: .95rem;
  font-weight: 900;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: .04em;
  text-shadow: 0 0 20px rgba(247,201,72,.35);
}

#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1;
}


/* ── トグルボタン（状態表示型） ── */
.btn-toggle {
  min-width: 84px;
  text-align: center;
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(247,201,72,.08);
}
.btn-toggle:hover {
  background: rgba(247,201,72,.18) !important;
  color: var(--accent) !important;
}

/* ── セパレータ ── */
.ctrl-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── ボタン共通 ── */
.btn-sm {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: .75rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-sm:hover { background: var(--border); color: var(--text); }
.btn-sm.active {
  background: rgba(247,201,72,.18);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-start {
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 900;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(247,201,72,.3);
  transition: transform .12s, box-shadow .12s;
}
.btn-start:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(247,201,72,.4); }

/* ── infoBar ── */
#infoBar {
  flex-shrink: 0;
  height: var(--info-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  overflow: hidden;
}

.chart-legend {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .68rem;
  color: var(--muted);
  white-space: nowrap;
}
.legend-box {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.eff2-box  { background: rgba(76,222,123,.5); }
.eff05-box { background: rgba(247,180,60,.45); }
.eff0-box  { background: rgba(255,92,110,.5); }
.eff1-box  { background: rgba(255,255,255,.06); border: 1px solid var(--border); }

#cellInfo {
  font-size: .75rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* ══════════════════════════════
   相性表
══════════════════════════════ */
.chart-table-wrap {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

table.ct {
  border-collapse: collapse;
  table-layout: fixed;
}

/* corner */
th.corner {
  width: 56px; min-width: 56px; height: 56px;
  background: var(--surface);
  border: none;
  position: sticky; top: 0; left: 0; z-index: 4;
}
th.corner::after {
  content: '';
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  background: linear-gradient(
    to top right,
    transparent calc(50% - .5px),
    rgba(255,255,255,.15) calc(50% - .5px),
    rgba(255,255,255,.15) calc(50% + .5px),
    transparent calc(50% + .5px)
  );
}
th.corner .c-atk { position: absolute; bottom: 4px; left: 5px; font-size: .48rem; color: var(--muted); }
th.corner .c-def { position: absolute; top: 4px; right: 5px; font-size: .48rem; color: var(--muted); }

/* defense header (column) */
th.hdr-def {
  width: 30px; min-width: 30px; height: 56px;
  vertical-align: bottom;
  padding: 3px 2px;
  position: sticky; top: 0; z-index: 3;
  background: var(--surface);
  cursor: pointer; user-select: none;
}
th.hdr-def .hdr-inner {
  writing-mode: vertical-rl;
  font-size: .62rem; font-weight: 700;
  color: #fff;
  padding: 3px 3px;
  border-radius: 4px;
  display: inline-block;
  white-space: nowrap;
}
th.hdr-def:hover .hdr-inner {
  outline: 2px solid rgba(255,255,255,.6);
}
th.hdr-def.hdr-off .hdr-inner { opacity: .3; }

/* attack header (row) */
th.hdr-atk {
  width: 56px; min-width: 56px; height: 30px;
  text-align: right;
  padding: 2px 4px;
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  cursor: pointer; user-select: none;
}
th.hdr-atk .hdr-inner {
  font-size: .62rem; font-weight: 700;
  color: #fff;
  padding: 2px 5px;
  border-radius: 4px;
  display: inline-block;
  white-space: nowrap;
}
th.hdr-atk:hover .hdr-inner {
  outline: 2px solid rgba(255,255,255,.6);
}
th.hdr-atk.hdr-off .hdr-inner { opacity: .3; }

/* data cells */
td.cell {
  width: 30px; min-width: 30px; height: 30px;
  text-align: center; vertical-align: middle;
  font-size: .75rem; font-weight: 900;
  cursor: default;
  border: 1px solid rgba(255,255,255,.05);
  transition: filter .1s;
}
td.cell.eff2  { background: rgba(76,222,123,.28);  color: #4cde7b; }
td.cell.eff05 { background: rgba(247,180,60,.22);  color: #f7b43c; }
td.cell.eff0  { background: rgba(255,92,110,.28);  color: #ff5c6e; }
td.cell.eff1  { background: rgba(255,255,255,.03); color: rgba(255,255,255,.18); }

/* ══ ゼブラストライプ（box-shadowで背景のみ・中身の色に干渉しない） ══ */
tbody tr:nth-child(even) td.cell {
  box-shadow: inset 0 0 0 9999px rgba(255,255,255,.06);
}

/* ══ eff1（等倍）は記号を非表示 ══ */
td.cell.eff1 { color: transparent; }

/* ══ セルホバースケール ══ */
td.cell:hover {
  transform: scale(1.35);
  z-index: 10;
  position: relative;
  box-shadow: 0 0 8px rgba(255,255,255,.2);
}

/* ══ stickyヘッダーにブラー ══ */
th.corner,
th.hdr-def,
th.hdr-atk {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: rgba(26,37,53,.85);
}
th.corner { background: rgba(26,37,53,.95); }
table.ct.grayout tr.row-dim th.hdr-atk { opacity: .55; }
table.ct.grayout tr.row-dim td.cell    { opacity: .35; filter: saturate(.3); }
table.ct.grayout th.col-dim            { opacity: .55; }
table.ct.grayout td.col-dim            { opacity: .35; filter: saturate(.3); }

/* ══ 選択のみ ══ */
table.ct.hide-unsel tr.row-dim { display: none; }
table.ct.hide-unsel th.col-dim,
table.ct.hide-unsel td.col-dim { display: none; }

/* ══ ハイライト ══ */
table.ct.hl-active td.cell:not(.hl-row):not(.hl-col):not(.hl-both) {
  opacity: .1;
}
table.ct.hl-active th.hdr-atk:not(.hl-hdr-atk) { opacity: .15; }
table.ct.hl-active th.hdr-def:not(.hl-hdr-def) { opacity: .15; }

td.cell.hl-row { opacity: 1 !important; background-color: var(--hl-row-bg) !important; }
td.cell.hl-col { opacity: 1 !important; background-color: var(--hl-col-bg) !important; }
td.cell.hl-both {
  opacity: 1 !important;
  transform: scale(1.3);
  box-shadow: 0 0 0 2px var(--hl-atk-color, #fff), 0 0 10px rgba(255,255,255,.3);
  z-index: 10;
  position: relative;
}
th.hl-hdr-atk { opacity: 1 !important; }
th.hl-hdr-def { opacity: 1 !important; }
th.hl-hdr-atk .hdr-inner { outline: 2px solid var(--hl-atk-color, #fff); }
th.hl-hdr-def .hdr-inner { outline: 2px solid var(--hl-def-color, #fff); }

/* ══ タイプカラー ══ */
.tc-ノーマル  { background: #9ba09e; }
.tc-ほのお    { background: #f9734a; }
.tc-みず      { background: #4d9be6; }
.tc-でんき    { background: #f7c948; color: #333; }
.tc-くさ      { background: #5da95d; }
.tc-こおり    { background: #72cfc0; }
.tc-かくとう  { background: #d05040; }
.tc-どく      { background: #a75ec1; }
.tc-じめん    { background: #d6b360; color: #333; }
.tc-ひこう    { background: #8fa8d8; }
.tc-エスパー  { background: #f85888; }
.tc-むし      { background: #91c121; color: #333; }
.tc-いわ      { background: #b8a148; color: #333; }
.tc-ゴースト  { background: #705898; }
.tc-ドラゴン  { background: #6050c8; }
.tc-あく      { background: #50413c; }
.tc-はがね    { background: #6abde0; color: #333; }
.tc-フェアリー { background: #f4b8e6; color: #333; }

/* ══════════════════════════════
   クイズ画面
══════════════════════════════ */
#quizView {
  height: 100dvh;
  overflow-y: auto;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(247,201,72,.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(76,222,123,.05) 0%, transparent 60%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
}
#quizInner {
  width: 100%;
  max-width: 520px;
  padding-top: 8px;
}

.btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .78rem;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 18px;
  transition: background .15s, color .15s;
}
.btn-back:hover { background: var(--border); color: var(--text); }

.progress-bar-wrap {
  width: 100%; height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 16px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .4s ease;
}

.score-row {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 16px;
}
.score-row b { color: var(--text); }

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px 20px;
  text-align: center;
  margin-bottom: 14px;
}
.q-label { font-size: .72rem; color: var(--muted); margin-bottom: 12px; letter-spacing: .06em; }
.q-types {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
}
.q-vs { color: var(--muted); font-size: .8rem; }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.choice-btn {
  background: var(--card);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 14px 10px;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 900;
  font-family: inherit;
  cursor: pointer;
  transition: background .13s, border-color .13s, transform .1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.choice-sub { font-size: .68rem; font-weight: 400; color: var(--muted); }
.choice-btn:hover:not(:disabled) {
  background: var(--border);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.choice-btn.correct { background: rgba(76,222,123,.2); border-color: var(--correct); color: var(--correct); }
.choice-btn.correct .choice-sub { color: var(--correct); }
.choice-btn.wrong   { background: rgba(255,92,110,.15); border-color: var(--wrong);   color: var(--wrong); }
.choice-btn:disabled { cursor: default; transform: none; }

.feedback {
  min-height: 30px;
  text-align: center;
  font-size: .88rem;
  font-weight: 700;
  padding: 4px 0;
}
.feedback.correct { color: var(--correct); }
.feedback.wrong   { color: var(--wrong); }

.btn-next {
  width: 100%; padding: 13px;
  background: var(--accent); color: #1a1a1a;
  border: none; border-radius: 12px;
  font-size: .95rem; font-weight: 900;
  font-family: inherit; cursor: pointer;
  margin-top: 10px;
  transition: transform .12s;
  display: none;
}
.btn-next:hover { transform: translateY(-2px); }

/* ══════════════════════════════
   結果画面
══════════════════════════════ */
#resultView {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 30%, rgba(247,201,72,.08) 0%, transparent 60%);
}
#resultInner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  width: 90%;
  max-width: 400px;
}
.result-score {
  font-size: 4rem; font-weight: 900;
  color: var(--accent); line-height: 1;
  margin-bottom: 6px;
  text-shadow: 0 0 40px rgba(247,201,72,.5);
}
.result-label { color: var(--muted); font-size: .88rem; margin-bottom: 20px; }
.result-rank  { font-size: 1.5rem; margin-bottom: 28px; }

.btn-retry {
  background: var(--accent); color: #1a1a1a;
  border: none; padding: 12px 32px;
  border-radius: 12px;
  font-size: .95rem; font-weight: 900;
  font-family: inherit; cursor: pointer;
  transition: transform .12s;
}
.btn-retry:hover { transform: translateY(-2px); }

@keyframes pop {
  0%   { transform: scale(.75); opacity: 0; }
  70%  { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}
.pop { animation: pop .25s ease forwards; }
