:root {
  color-scheme: dark;
  /* hirobareview の宣伝画像に合わせたシアン系ネオン + 紺グラデ */
  --bg-1: #04070e;
  --bg-2: #0b1328;
  --bg-3: #070c1a;
  --panel: #15203f;
  --panel-2: #1c2a55;
  --border: #2f3f7a;
  --text: #e6f6ff;
  --dim: #96c4e0;
  --neon: #7ef9ff;
  --accent: #00d9ff;
  --accent-d: #021e2a;
  --err: #f87171;
  --grid: rgba(126, 249, 255, 0.06);

  --row-min-h: 76px;
  --icon: 56px;
  --gap: 6px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg-2); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
  padding: 0 0 max(env(safe-area-inset-bottom), 16px);
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg-2);
  background-image:
    radial-gradient(420px 420px at 12% 8%, rgba(88,200,255,0.30), transparent 60%),
    radial-gradient(380px 380px at 92% 12%, rgba(110,90,240,0.26), transparent 60%),
    radial-gradient(520px 520px at 50% 95%, rgba(40,120,235,0.24), transparent 62%),
    linear-gradient(rgba(126,249,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126,249,255,0.05) 1px, transparent 1px),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  background-size: auto, auto, auto, 40px 40px, 40px 40px, auto;
  background-attachment: fixed;
}
button { font-family: inherit; cursor: pointer; }

/* ---------- meta（ヘッダー兼操作バー） ---------- */
.primary {
  appearance: none; border: 0;
  background: var(--neon); color: var(--accent-d);
  font-weight: 800; font-size: 14px;
  padding: 9px 16px;
  border-radius: 999px;
  box-shadow: 0 0 14px rgba(126,249,255,0.5);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.primary:active { filter: brightness(0.92); }

.meta {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: rgba(11, 19, 40, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--panel-2);
}
.meta .nick {
  display: flex; flex-direction: column; gap: 3px;
  min-width: 0;
  flex: 0 1 180px;
}
.meta .nick span { font-size: 10px; color: var(--dim); letter-spacing: 0.04em; }
.meta input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 14px;
  width: 100%;
  min-width: 0;
}
.meta input[type="text"]:focus {
  outline: none;
  border-color: var(--neon);
  box-shadow: 0 0 0 2px rgba(126,249,255,0.25);
}
.meta .toggle {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--dim);
  padding-top: 14px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.meta .toggle input { width: 16px; height: 16px; accent-color: var(--neon); }
.meta #exportBtn { margin-left: auto; }

/* ---------- board（撮影対象） ---------- */
.board {
  margin: 12px;
  background-color: rgba(11, 19, 40, 0.55);
  background-image:
    linear-gradient(rgba(126,249,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126,249,255,0.05) 1px, transparent 1px);
  background-size: 40px 40px, 40px 40px;
  border: 1px solid var(--panel-2);
  border-radius: 14px;
  padding: 12px 12px 10px;
}
.board-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.board-head-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.board-title {
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--text);
  font-weight: 800;
}
.board-nick {
  font-size: 12px;
  color: var(--dim);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-nick:empty { display: none; }
.board-banner {
  height: 40px;
  width: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.tiers { display: flex; flex-direction: column; gap: 8px; }
.tier {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  align-items: stretch;
  background: transparent;
  border: 2px solid currentColor;
  border-radius: 10px;
  overflow: hidden;
}
.tier-label {
  font-weight: 900;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  color: inherit;
  text-shadow: 0 0 8px currentColor, 0 0 14px currentColor;
  position: relative;
  z-index: 1;
}
.tier-row {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: var(--gap);
  padding: 6px;
  min-height: var(--row-min-h);
  position: relative;
  z-index: 1;
}

/* 蛍光カラー：A/B/C/D は --tier-X 変数（JS から注入）を使った1ルールに集約 */
.tier[data-tier="A"], .tier[data-tier="B"],
.tier[data-tier="C"], .tier[data-tier="D"] {
  color: var(--c);
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 45%, transparent);
}
.tier[data-tier="A"] { --c: var(--tier-A); }
.tier[data-tier="B"] { --c: var(--tier-B); }
.tier[data-tier="C"] { --c: var(--tier-C); }
.tier[data-tier="D"] { --c: var(--tier-D); }

/* S は虹色枠（::before + mask-composite で角丸を維持） */
.tier[data-tier="S"] {
  position: relative;
  border: 0;
  box-shadow: 0 0 12px rgba(255,255,255,0.25);
}
.tier[data-tier="S"]::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 10px;
  padding: 2px;
  background: linear-gradient(90deg,#ff4d6d,#ff9f43,#fde047,#4ade80,#38bdf8,#c084fc);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}
.tier[data-tier="S"] .tier-label {
  background: linear-gradient(180deg,#ff4d6d 0%,#fde047 50%,#38bdf8 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  text-shadow: 0 0 10px rgba(255,255,255,0.4);
}

.icon-tile {
  width: var(--icon);
  height: var(--icon);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-drag: none;
}
.icon-tile img {
  width: 100%; height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}
.icon-tile:active { transform: scale(0.96); }

.rank-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--neon);
  text-align: center;
  letter-spacing: 0.04em;
}

/* ---------- 使い方 ---------- */
.howto {
  margin: 12px;
  background: rgba(11, 19, 40, 0.6);
  border: 1px solid var(--panel-2);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
}
.howto summary {
  cursor: pointer;
  color: var(--neon);
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 0;
}
.howto ul { margin: 8px 0 4px; padding-left: 20px; color: var(--dim); }
.howto li { margin: 4px 0; line-height: 1.55; }
.howto b { color: var(--text); }

/* ---------- pool ---------- */
.pool-wrap { margin: 4px 12px 12px; }
.pool-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--dim);
  padding: 4px 2px 6px;
}
.pool-head .count {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--text);
}
.pool {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: 8px;
  background: rgba(11,19,40,0.55);
  border: 1px solid var(--panel-2);
  border-radius: 12px;
  min-height: 80px;
}
.pool:empty::after {
  content: "全部振り分けたよ！";
  color: var(--dim);
  font-size: 12px;
  padding: 12px;
}

/* ---------- bottom sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}
.sheet-panel {
  position: relative;
  background: var(--bg);
  border-top: 1px solid var(--panel-2);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 16px 14px max(env(safe-area-inset-bottom), 14px);
  animation: slideUp 0.16s ease-out;
}
@keyframes slideUp { from { transform: translateY(20%); opacity: 0.3; } to { transform: translateY(0); opacity: 1; } }
.sheet-target {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--panel-2);
  margin-bottom: 12px;
}
.sheet-target img {
  width: 48px; height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
}
.sheet-target div { font-size: 14px; font-weight: 700; }

.sheet-actions { display: grid; gap: 8px; }
.sheet-actions .row { display: grid; gap: 6px; grid-template-columns: repeat(5, 1fr); }
.sheet-actions button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 4px;
  font-weight: 700;
  font-size: 16px;
}
.sheet-actions .tier-btn {
  background: rgba(11,19,40,0.6);
  border-width: 2px;
  font-size: 20px;
  font-weight: 900;
}
.sheet-actions .tier-btn[data-tier="S"] {
  color: transparent;
  background: linear-gradient(135deg,#ff4d6d,#fde047,#38bdf8,#c084fc);
  -webkit-background-clip: text; background-clip: text;
  border-color: #fde047;
  box-shadow: 0 0 12px rgba(255,255,255,0.3);
  text-shadow: 0 0 6px rgba(255,255,255,0.6);
}
.sheet-actions .tier-btn[data-tier="A"],
.sheet-actions .tier-btn[data-tier="B"],
.sheet-actions .tier-btn[data-tier="C"],
.sheet-actions .tier-btn[data-tier="D"] {
  color: var(--c);
  border-color: var(--c);
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 45%, transparent);
  text-shadow: 0 0 6px var(--c);
}
.sheet-actions .tier-btn[data-tier="A"] { --c: var(--tier-A); }
.sheet-actions .tier-btn[data-tier="B"] { --c: var(--tier-B); }
.sheet-actions .tier-btn[data-tier="C"] { --c: var(--tier-C); }
.sheet-actions .tier-btn[data-tier="D"] { --c: var(--tier-D); }
.sheet-actions .tier-btn.current { outline: 2px solid var(--neon); outline-offset: 2px; }

/* tier 内の並びプレビュー（編集時の現在地） */
.tier-preview {
  margin-top: 8px;
  padding: 10px;
  background: rgba(11,19,40,0.6);
  border: 1px solid var(--panel-2);
  border-radius: 10px;
}
.tier-preview .label {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.tier-preview-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  max-height: 40vh;
  overflow-y: auto;
}
.tier-preview-row .icon-tile {
  width: 48px; height: 48px;
  pointer-events: none;
  cursor: default;
  flex: 0 0 auto;
}
.tier-preview-row .icon-tile.selected {
  outline: 3px solid var(--neon);
  outline-offset: 2px;
  box-shadow: 0 0 14px rgba(126,249,255,0.75);
  transform: translateY(-2px);
}

.sheet-actions .move-row { display: grid; gap: 6px; grid-template-columns: 1fr 1fr 1fr; margin-top: 4px; }
.sheet-actions .move-row button { font-size: 13px; padding: 10px 4px; font-weight: 600; }
.sheet-actions .move-row button:disabled { color: #6b7195; }
.sheet-actions .move-row .danger { color: var(--err); border-color: rgba(248,113,113,0.4); }

.sheet-done {
  margin-top: 12px;
  width: 100%;
  appearance: none;
  background: transparent;
  color: var(--neon);
  border: 2px solid var(--neon);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 0 0 10px rgba(126,249,255,0.35);
  text-shadow: 0 0 6px rgba(126,249,255,0.5);
}
.sheet-done:active { background: rgba(126,249,255,0.12); }

/* ---------- busy ---------- */
.busy {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
}
.busy-panel {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 12px;
  padding: 16px 22px;
  font-size: 14px;
  color: var(--text);
}

/* ---------- desktop ---------- */
@media (min-width: 720px) {
  .board, .pool-wrap, .meta { max-width: 720px; margin-inline: auto; }
  .topbar { padding-inline: 24px; }
}
