:root {
  --bg: #eceff3;
  --bg-deep: #d9dee5;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-soft: #f7f9fc;
  --line: #cdd4de;
  --line-strong: #aeb7c4;
  --text: #26313f;
  --muted: #5d6b7d;
  --primary: #4a5c77;
  --primary-strong: #34455f;
  --accent: #687991;
  --danger: #b64f59;
  --success: #2f7d62;
  --shadow: 0 18px 40px rgba(41, 52, 69, 0.10);
  --radius-xl: 24px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.8), transparent 26%),
    linear-gradient(180deg, #f8fafc 0%, var(--bg) 52%, var(--bg-deep) 100%);
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { appearance: none; }

.site-shell {
  width: min(1280px, calc(100% - 28px));
  margin: 0 auto;
  padding: 20px 0 34px;
}
.admin-shell { width: min(1200px, calc(100% - 28px)); }
.portal-main, .page-shell, .admin-main { display: grid; gap: 22px; }
.two-col-block {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}
.layout-grid {
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
}

.card-surface, .play-card, .side-card, .hero-card, .portal-hero, .panel-block {
  border: 1px solid rgba(173, 184, 198, 0.85);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(245,248,252,0.95));
  box-shadow: var(--shadow);
}
.common-frame {
  border-radius: 22px;
}

.site-header, .site-footer { margin-bottom: 22px; }
.site-footer { margin-top: 22px; margin-bottom: 0; }
.site-header-inner, .site-footer-inner {
  display: flex;
  gap: 18px;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
}
.brand-block { display: flex; flex-direction: column; gap: 4px; }
.brand-link { font-size: 1.15rem; font-weight: 800; letter-spacing: 0.02em; }
.brand-sub, .footer-brand p, .section-head p, .hero-lead, .panel-note, .empty-note, .subtle, small {
  color: var(--muted);
}
.brand-sub { font-size: 0.93rem; }
.topnav, .hero-actions, .action-row, .difficulty-buttons, .ranking-switches, .auth-links, .footer-links, .admin-actions-bottom {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.topnav a, .footer-links a {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 700;
}
.topnav a:hover, .footer-links a:hover, .topnav a.is-current {
  border-color: var(--line-strong);
  color: var(--primary-strong);
  background: #eef2f7;
}
.topnav a.is-current {
  box-shadow: inset 0 0 0 1px rgba(52,69,95,0.06);
}
.footer-brand strong { display: block; margin-bottom: 6px; }
.footer-brand p { margin-bottom: 0; }

.page-hero, .portal-hero, .hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 22px;
  padding: 28px;
}
.hero-grid-mini, .hero-meta, .admin-stat-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
}
.admin-stat-grid.four-cols { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mini-stat, .meta-box, .status-box, .difficulty-card, .summary-row, .best-row, .rank-row, .rank-preview-row, .inline-form-card {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}
.mini-stat span, .meta-label, .status-label {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 8px;
}
.mini-stat strong, .meta-box strong, .status-box strong { font-size: 1.08rem; }
.accent, .mini-stat.accent, .meta-box.accent {
  background: linear-gradient(180deg, #eff3f8, #e3e9f1);
  border-color: #bbc5d1;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 4vw, 2.9rem); line-height: 1.2; margin-bottom: 12px; }
h2 { font-size: 1.35rem; margin-bottom: 10px; }
h3 { font-size: 1.03rem; margin-bottom: 8px; }
.eyebrow {
  margin: 0 0 10px;
  color: var(--primary-strong);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
}
.hero-lead { font-size: 1.02rem; line-height: 1.8; margin-bottom: 0; }

.section-block, .play-card, .side-card { padding: 24px; }
.play-card, .side-card { border-radius: 24px; }
.side-card { display: grid; gap: 18px; align-content: start; }
.panel-block { padding: 18px; border-radius: 18px; }
.section-head { margin-bottom: 18px; }
.section-head.compact { margin-bottom: 14px; }

.link-btn { display: inline-flex; align-items: center; justify-content: center; }
.difficulty-btn, .rank-btn, .secondary-btn, .primary-btn, .danger-btn {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  font-weight: 800;
}
.primary-btn {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: #fff;
  box-shadow: 0 10px 24px rgba(52,69,95,0.22);
}
.secondary-btn, .difficulty-btn, .rank-btn {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
}
.danger-btn {
  background: linear-gradient(180deg, #d26873, var(--danger));
  color: #fff;
}
.primary-btn:hover, .secondary-btn:hover, .difficulty-btn:hover, .rank-btn:hover, .danger-btn:hover {
  transform: translateY(-1px);
}
.difficulty-btn.is-active, .rank-btn.is-active, .secondary-btn.is-active {
  background: #e8eef6;
  border-color: #b7c2cf;
  color: var(--primary-strong);
}

.difficulty-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.difficulty-card-head { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}
.pill-accent { background: #dfe7f1; color: var(--primary-strong); }
.mini-specs { display: grid; gap: 10px; margin: 0; }
.mini-specs div { display: flex; justify-content: space-between; gap: 12px; }
.mini-specs dt { color: var(--muted); }
.mini-specs dd { margin: 0; font-weight: 700; }

.toolbar {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 280px) 1fr;
  margin-bottom: 18px;
}
.name-wrap, .difficulty-wrap { display: grid; gap: 8px; }
label span, .toolbar-label { color: var(--muted); font-size: 0.92rem; font-weight: 700; }
input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}
input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus {
  outline: 2px solid rgba(74,92,119,0.15);
  border-color: var(--primary);
}

.status-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.board-info {
  margin: 14px 0 12px;
  padding: 12px 14px;
  border-left: 4px solid var(--primary);
  background: rgba(236, 241, 247, 0.92);
  border-radius: 14px;
  color: var(--muted);
  font-weight: 700;
}
.board-scroll {
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f4f7fb);
}
.game-board {
  display: grid;
  gap: var(--cell-gap, 4px);
  width: max-content;
  user-select: none;
  touch-action: manipulation;
}
.cell {
  width: var(--cell-size, 34px);
  height: var(--cell-size, 34px);
  padding: 0;
  border-radius: 8px;
  border: 1px solid #8f9bad;
  background: linear-gradient(180deg, #fefefe, #d7dee7);
  color: #334155;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(125, 139, 158, 0.55), inset 0 1px 0 rgba(255,255,255,0.95);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.cell.is-actionable {
  cursor: pointer;
}
.cell.is-actionable:hover {
  transform: translateY(-1px);
  border-color: #5c6a7d;
  background: linear-gradient(180deg, #ffffff, #d1d9e4);
  box-shadow: 0 3px 0 rgba(92, 106, 125, 0.55), inset 0 1px 0 rgba(255,255,255,0.98);
}
.cell:focus-visible {
  outline: 2px solid rgba(74,92,119,0.4);
  outline-offset: 1px;
}
.cell.revealed,
.cell.is-static {
  cursor: default;
}
.cell.revealed {
  background: linear-gradient(180deg, #f7f9fc, #e6ebf2);
  border-color: #c5ced9;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
.cell.flagged {
  background: linear-gradient(180deg, #eef3f8, #cfd8e4);
  border-color: #6f8096;
}
.cell.mine { background: linear-gradient(180deg, #f8d8dc, #efb6bd); }
.cell-1 { color: #2b5ed9; }
.cell-2 { color: #1e7d4f; }
.cell-3 { color: #b34a36; }
.cell-4 { color: #5f4cbf; }
.cell-5 { color: #932e3d; }
.cell-6 { color: #0f7281; }
.cell-7 { color: #4b5563; }
.cell-8 { color: #111827; }

.message-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  min-height: 58px;
  line-height: 1.7;
}
.leaderboard-box, .leaderboard-list, .rank-preview-list, .admin-ranking-list, .summary-list, .local-best-list, .reset-card-list {
  display: grid;
  gap: 12px;
}
.rank-preview-row, .rank-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}
.rank-order, .rank-num {
  min-width: 54px;
  text-align: center;
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 800;
  background: #e8eef6;
  color: var(--primary-strong);
}
.rank-player, .rank-name, .summary-name, .best-name { font-weight: 700; }
.rank-time, .best-time { font-weight: 800; }

.admin-main { gap: 22px; }
.admin-panels { align-items: start; }
.inline-form-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
}
.inline-form-card.is-full { grid-column: 1 / -1; }
.reset-card-list.three-stack { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack-form { display: grid; gap: 14px; }
.compact-form { max-width: 420px; }
.alert-box {
  padding: 14px 16px;
  border-radius: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
}
.alert-success { background: #eefaf4; border-color: #9dcfb5; color: #205d46; }
.alert-error { background: #fff1f2; border-color: #e6b2b8; color: #932e3d; }
.alert-info { background: #eef4fb; border-color: #b9c7d8; color: #3d516b; }
.admin-actions-bottom { justify-content: flex-end; }

.admin-auth-body { min-height: 100vh; }
.admin-auth-wrap {
  min-height: auto;
  display: grid;
  place-items: center;
  padding: 12px 0 0;
}
.narrow-wrap { width: 100%; }
.admin-auth-card {
  width: min(560px, 100%);
  padding: 28px;
  border-radius: 24px;
}

@media (max-width: 1100px) {
  .page-hero, .portal-hero, .hero-card, .layout-grid, .two-col-block, .difficulty-cards, .admin-stat-grid.four-cols, .reset-card-list.three-stack {
    grid-template-columns: 1fr;
  }
  .toolbar { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .site-header-inner, .site-footer-inner { flex-direction: column; align-items: flex-start; }
  .status-panel, .hero-grid-mini, .hero-meta, .admin-stat-grid { grid-template-columns: 1fr; }
  .inline-form-card { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .site-shell, .admin-shell { width: min(100% - 18px, 100%); }
  .site-header-inner, .site-footer-inner, .page-hero, .portal-hero, .hero-card, .play-card, .side-card, .section-block, .admin-auth-card { padding: 18px; }
  .cell { width: var(--cell-size-mobile, 28px); height: var(--cell-size-mobile, 28px); }
  .board-scroll { justify-content: flex-start; }
}

.account-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.account-nav a,
.auth-helper-links a {
  color: var(--primary-strong);
  text-decoration: none;
  font-weight: 700;
}
.account-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: #e8eef6;
  color: var(--primary-strong);
  font-size: 0.92rem;
  font-weight: 700;
}
.field-help {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.6;
}
.account-panel,
.account-summary-box {
  display: grid;
  gap: 12px;
}
.account-panel-head {
  display: grid;
  gap: 4px;
}
.account-panel-actions,
.compact-actions,
.auth-helper-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.account-stats-list {
  display: grid;
  gap: 10px;
}
.account-stats-list.detailed {
  gap: 14px;
}
.account-stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
}
.account-stat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: flex-end;
  color: var(--muted);
  font-weight: 600;
}
.account-stat-best {
  color: var(--primary-strong);
  font-weight: 700;
  text-align: right;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.checkbox-row input {
  width: 18px;
  height: 18px;
}
.admin-stat-grid.five-cols {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.profile-shell {
  display: grid;
  gap: 22px;
}
.auth-helper-links {
  margin-top: 14px;
}

@media (max-width: 1100px) {
  .admin-stat-grid.five-cols {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 820px) {
  .account-stat-row {
    grid-template-columns: 1fr;
  }
  .account-stat-best,
  .account-stat-meta {
    text-align: left;
    justify-content: flex-start;
  }
}
