:root {
  --sidebar-w: 220px;
  --bg: #f5f3ef;
  --primary: #c0392b;
  --primary-dark: #962d22;
  --gold: #e8b931;
  --dark: #2b1d1d;
  --text: #333;
  --muted: #888;
  --border: #ddd;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ---------------------------------------------------------- レイアウト（左／右） */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #7b1e16, var(--dark));
  color: #fff;
  transition: margin-left .3s ease;
}
.menu-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-title {
  padding: 24px 20px;
  font-size: 20px;
  font-weight: bold;
  color: var(--gold);
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.sidebar-title span { font-size: 15px; color: #fff; }

.menu { list-style: none; margin: 0; padding: 12px 0; }
.menu a {
  display: block;
  padding: 14px 24px;
  color: #f2e6e6;
  text-decoration: none;
  border-left: 4px solid transparent;
}
.menu a:hover { background: rgba(255,255,255,.08); }
.menu a.active {
  background: rgba(255,255,255,.12);
  border-left-color: var(--gold);
  color: #fff;
  font-weight: bold;
}

.menu-group {
  padding: 16px 24px 6px;
  font-size: 12px;
  color: rgba(255,255,255,.55);
  letter-spacing: .1em;
}

/* ログイン中のユーザ */
.sidebar-user {
  margin: 8px 16px;
  padding: 14px 12px;
  border-top: 1px solid rgba(255,255,255,.15);
}
.sidebar-user-name { font-weight: bold; color: #fff; }
.sidebar-user-role { font-size: 12px; color: rgba(255,255,255,.65); margin: 2px 0 10px; }
.btn-logout { background: rgba(255,255,255,.15); }
.btn-logout:hover { background: rgba(255,255,255,.3); }

.content { flex: 1; min-width: 0; padding: 20px 28px 40px; }

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.content-header h1 { margin: 0; font-size: 24px; }
.content-header .btn-toggle { margin-left: auto; flex-shrink: 0; }

/* ---------------------------------------------------------- 共通部品 */
.btn {
  border: none;
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 15px;
  cursor: pointer;
  color: #fff;
  background: #777;
  transition: background .2s, opacity .2s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
a.btn { display: inline-block; text-decoration: none; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-danger { background: #333; }
.btn-danger:hover:not(:disabled) { background: #000; }
.btn-secondary { background: #8a8a8a; }
.btn-toggle { background: var(--dark); min-width: 80px; }
.btn-large { padding: 12px 36px; font-size: 18px; font-weight: bold; }
.btn-small { padding: 5px 12px; font-size: 13px; }

.card {
  background: #fff;
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-header h2 { margin: 0; }

.hint { color: var(--muted); margin: 0 0 12px; }

.flash { padding: 10px 16px; border-radius: 6px; margin-bottom: 12px; }
.flash-success { background: #e6f4ea; color: #1e6b35; }
.flash-error { background: #fdecea; color: #a12a1f; }

/* ---------------------------------------------------------- フォーム */
.form-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.form-row label { width: 140px; flex-shrink: 0; font-weight: bold; }
.form-row input[type="text"],
.form-row input[type="password"],
.form-row input[type="number"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  width: 280px;
}
.form-row input[type="number"] { width: 120px; }
.form-row-top { align-items: flex-start; }
.radio-group { display: flex; gap: 24px; padding-top: 2px; }
.form-row .radio { width: auto; font-weight: normal; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.form-row .radio input { width: 18px; height: 18px; margin: 0; }
.form-actions { padding-left: 152px; }
.form-actions .btn + .btn { margin-left: 8px; }
.hint-inline { color: var(--muted); font-size: 13px; }
.photo-preview { max-width: 160px; max-height: 160px; border-radius: 8px; object-fit: cover; }

/* ---------------------------------------------------------- 一覧 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid #eee; text-align: left; }
.table th { background: #faf7f2; white-space: nowrap; }
.table td.nowrap { white-space: nowrap; }
.table td.actions { white-space: nowrap; }
.table td.actions form { display: inline; margin-left: 4px; }
.table tr.row-disabled td { color: #aaa; background: #fafafa; }

.tag {
  display: inline-block;
  white-space: nowrap;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: #eee;
  color: #555;
}
.tag-admin { background: var(--gold); color: #3a2a00; }
.tag-user { background: #e6eef8; color: #2a4a70; }

/* ---------------------------------------------------------- ログイン画面 */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #7b1e16, var(--dark));
}
.login-box {
  width: 360px; max-width: 92vw;
  background: #fff;
  border-radius: 12px;
  padding: 32px 32px 28px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.login-title {
  text-align: center;
  font-size: 22px; font-weight: bold;
  color: var(--primary);
  margin-bottom: 20px;
}
.login-title span { font-size: 16px; color: var(--text); }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-weight: bold; font-size: 14px; margin-top: 8px; }
.login-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}
.login-form .btn { margin-top: 18px; }

.thumb {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.thumb-empty, .photo-empty {
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: bold; background: #a77;
}

/* ---------------------------------------------------------- 抽選画面 */
/* 画面上部の1行（右端の「非表示」ボタンと同じ行に左寄せで並べる） */
.draw-controls {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: nowrap; white-space: nowrap;
  min-width: 0;
}
.draw-controls label { font-weight: bold; font-size: 17px; }
/* 画面幅が狭い場合も1行に収まるよう、ボタンの余白を幅に合わせて縮める */
.draw-controls .btn-large { padding: 12px clamp(14px, 2vw, 36px); }
.draw-controls select {
  font-size: 16px; padding: 9px 10px;
  border-radius: 6px; border: 1px solid var(--border);
}
.draw-status {
  display: flex; align-items: center; gap: 12px;
  min-height: 20px; margin: -6px 0 8px;
}
.notify-status { font-size: 13px; color: #1e6b35; }
.remaining { margin-left: auto; color: var(--muted); }

.wall-stage {
  position: relative;
  height: 62vh;
  min-height: 380px;
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
  perspective: 1400px;
  background: radial-gradient(ellipse at center, #5a1a14 0%, #1d0f0f 75%);
}
/* 抽選画面：抽選エリアを画面下端まで広げる（画面の高さに収め、残りを全て抽選エリアにする） */
.content-fill {
  display: flex; flex-direction: column;
  min-height: 100vh; /* 画面が低すぎる場合は抽選エリアの最小高さを保ってスクロール */
  padding-bottom: 20px;
}
.content-fill > * { flex-shrink: 0; }
.content-fill .wall-stage {
  flex: 1 1 auto;
  height: auto;
  margin-bottom: 0;
}
/* 抽選画面の背景写真（抽選エリアは半透明にして写真を透かす） */
.draw-bg {
  background: #2b1d1d url("../images/neusoft.jpg") center / cover no-repeat;
}
/* 各項目の行：背景写真の色（空 #dcf0fd・建物 #a1b2c8・石材 #4d5c68・芝 #3d580c）に合わせる */
.draw-bg {
  --photo-sky: 220, 240, 253;
  --photo-steel: 161, 178, 200;
  --photo-slate: #2f3d48;
  --photo-grass: #3d580c;
}
.draw-bg .content-header,
.draw-bg .draw-status {
  background: linear-gradient(90deg, rgba(var(--photo-sky), .88), rgba(var(--photo-steel), .82));
  border: 1px solid rgba(255,255,255,.6);
  border-bottom: 3px solid var(--photo-grass);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--photo-slate);
  box-shadow: 0 2px 10px rgba(21,35,31,.25);
  backdrop-filter: blur(4px);
}
.draw-bg .draw-status { margin: -6px 0 10px; padding: 4px 12px; border-bottom-width: 2px; }
.draw-bg .draw-controls label { color: var(--photo-slate); }
.draw-bg .draw-controls select { border-color: rgba(77,92,104,.35); color: var(--photo-slate); }
.draw-bg .remaining { color: var(--photo-slate); font-weight: bold; }
.draw-bg .voice-status { color: #4d5c68; }
.draw-bg .notify-status { color: var(--photo-grass); font-weight: bold; }
.draw-bg .btn-toggle { background: #4d5c68; }
.draw-bg .wall-stage {
  background: radial-gradient(ellipse at center, rgba(60,18,14,.30) 0%, rgba(20,10,10,.62) 80%);
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
}
.wall-stage.spinning { box-shadow: 0 0 0 4px var(--gold) inset, 0 0 30px rgba(232,185,49,.5); }

.wall {
  position: absolute;
  left: 50%; top: 50%;
  width: 0; height: 0;
  transform-style: preserve-3d;
}
.wall-card {
  position: absolute;
  left: 0; top: 0;
  display: flex; flex-direction: column;
  font-size: 40px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  backface-visibility: hidden;
}
.wall-photo { width: 100%; flex: 1; min-height: 0; object-fit: cover; display: flex; font-size: inherit; }
.wall-name {
  flex-shrink: 0;
  height: 28px; line-height: 28px;
  font-size: 13px; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 4px;
}
.wall-stage.spinning .wall-card { filter: blur(1px); }

/* 長方形・龍・GUN：ステージ全体を使う 2D 配置 */
.wall-rectangle, .wall-dragon, .wall-gun, .wall-globe {
  left: 0; top: 0;
  width: 100%; height: 100%;
  transform-style: flat;
}
.round-card {
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 10px rgba(232,185,49,.45);
}
.dragon-head {
  position: absolute;
  left: 0; top: 0;
  line-height: 1;
  filter: drop-shadow(0 0 12px rgba(232,185,49,.8));
}

/* 🌎 */
.globe-sphere {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  /* 半透明の海：裏側の写真が透けて見える */
  background: radial-gradient(circle at 35% 30%, rgba(120,190,255,.55) 0%, rgba(30,90,170,.6) 45%, rgba(5,25,70,.75) 100%);
  box-shadow: 0 0 40px 8px rgba(110,180,255,.45), inset -20px -20px 60px rgba(0,0,0,.45);
}
.globe-card { will-change: transform; }
.wall-stage.spinning .globe-card { filter: none; }

/* GUN */
.gunman {
  position: absolute;
  z-index: 5;
  filter: drop-shadow(0 0 14px rgba(255,255,255,.35));
}
.gunman svg { width: 100%; height: 100%; display: block; overflow: visible; }
.bullet {
  position: absolute;
  left: -9px; top: -2px;
  width: 18px; height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255,213,74,0), #ffd54a 60%, #fff);
  box-shadow: 0 0 6px #ffd54a;
  z-index: 6;
  pointer-events: none;
}
.wall-card.hit { animation: hit .3s ease-out; }
@keyframes hit {
  0%   { filter: brightness(2.5); box-shadow: 0 0 0 4px #ff3b30, 0 0 24px #ff3b30; }
  100% { filter: none; }
}
.spark {
  position: absolute;
  width: 60px; height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #ffd54a 30%, rgba(255,80,0,.6) 55%, rgba(255,80,0,0) 70%);
  z-index: 7;
  pointer-events: none;
  animation: spark .4s ease-out forwards;
}
@keyframes spark {
  0%   { transform: scale(.2); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

.wall-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #f2e6e6; margin: 0;
}
.wall-empty[hidden] { display: none; }

.badge {
  background: var(--gold); color: var(--dark);
  font-weight: bold; font-size: 13px;
  padding: 3px 10px; border-radius: 12px;
  min-width: 64px; text-align: center;
}

/* ---------------------------------------------------------- 当選者 大表示 */
.overlay {
  position: fixed; inset: 0;
  background: rgba(20, 5, 5, .88);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.overlay[hidden] { display: none; }
.overlay-inner { text-align: center; color: #fff; padding: 20px; max-width: 95vw; }
.overlay-title {
  font-size: 48px; font-weight: bold; color: var(--gold);
  margin-bottom: 30px;
  text-shadow: 0 0 20px rgba(232,185,49,.6);
}
.overlay-winners {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 30px;
  margin-bottom: 24px; max-height: 70vh; overflow-y: auto;
}
.big-winner { animation: pop .6s ease both; }
.big-photo {
  width: 300px; height: 300px;
  border-radius: 16px; object-fit: cover;
  border: 6px solid var(--gold);
  box-shadow: 0 0 40px rgba(232,185,49,.5);
  font-size: 120px;
}
.overlay-winners[data-count="3"] .big-photo,
.overlay-winners[data-count="4"] .big-photo { width: 220px; height: 220px; font-size: 90px; }
.overlay-winners[data-count="5"] .big-photo { width: 180px; height: 180px; font-size: 72px; }
.big-name { font-size: 32px; font-weight: bold; margin-top: 12px; }
.big-dept { font-size: 18px; color: #e8d8c8; }
.overlay-note { color: #ffcf9e; }

@keyframes pop {
  0%   { transform: scale(.3); opacity: 0; }
  70%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------------------------------------------------------- 音声操作 */
.btn-voice { background: #8a8a8a; }
.btn-voice.on { background: #1e8e3e; animation: voice-pulse 1.6s ease-in-out infinite; }
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(30,142,62,.5); }
  50%      { box-shadow: 0 0 0 6px rgba(30,142,62,0); }
}
.voice-status { font-size: 13px; color: var(--muted); }
.voice-status[data-kind="matched"] { color: #1e8e3e; font-weight: bold; }
.voice-status[data-kind="error"] { color: #c0392b; }

/* ---------------------------------------------------------- MFA（ログイン画面） */
.login-box-setup { width: 420px; }
.login-hint { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.login-cancel { margin-top: 10px; text-align: center; font-size: 13px; color: var(--muted); }
.mfa-setup {
  margin: 14px 0 4px;
  padding: 14px 16px;
  border: 2px solid var(--gold);
  border-radius: 10px;
  background: #fffbea;
  text-align: center;
}
.mfa-setup-title { font-weight: bold; color: var(--primary); margin-bottom: 6px; }
.mfa-steps { text-align: left; font-size: 13px; margin: 0 0 10px; padding-left: 20px; }
.mfa-steps li + li { margin-top: 4px; }
.mfa-qr { width: 220px; height: 220px; background: #fff; }
.mfa-manual { margin-top: 6px; font-size: 12px; color: var(--muted); }
.mfa-manual summary { cursor: pointer; }
.mfa-manual code { display: block; margin-top: 4px; word-break: break-all; font-size: 13px; color: var(--text); letter-spacing: .05em; }
