/* 縁日・和風テーマ */
:root {
  --night: #141a2e;
  --night-2: #1f2742;
  --urushi: #2a1410;
  --urushi-2: #1a0c08;
  --shu: #c9171e;
  --shu-light: #e0362b;
  --shu-dark: #5e0b0e;
  --kin: #d4a640;
  --kin-light: #f3d98a;
  --kin-dark: #8a6420;
  --kinari: #f4efe4;
  --washi: #f7f1e3;
  --ink: #2b1d16;
  --ink-muted: #7a6a58;
  --on-dark-muted: #d9c9a5;
  --mincho: "Shippori Mincho B1", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --gothic: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --gold-grad: linear-gradient(135deg, #8a6420, #f6e3a1 30%, #b8862b 55%, #f3d98a 80%, #8a6420);
}

* { box-sizing: border-box; }

html { background: var(--night); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--kinari);
  font-family: var(--gothic);
  line-height: 1.5;
  background-color: var(--night);
  background-image:
    radial-gradient(ellipse 90% 40% at 50% 0%, rgba(255, 150, 70, 0.22), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='24' viewBox='0 0 48 24'%3E%3Cg fill='none' stroke='%23f3d98a' stroke-opacity='0.07' stroke-width='1.2'%3E%3Cpath d='M2 24a22 22 0 0 1 44 0M8 24a16 16 0 0 1 32 0M14 24a10 10 0 0 1 20 0M20 24a4 4 0 0 1 8 0'/%3E%3Cpath d='M-22 12a22 22 0 0 1 44 0M-16 12a16 16 0 0 1 32 0M-10 12a10 10 0 0 1 20 0M26 12a22 22 0 0 1 44 0M32 12a16 16 0 0 1 32 0M38 12a10 10 0 0 1 20 0'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(var(--night-2), var(--night) 60%);
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }

/* ---- 提灯 ---- */
.lanterns {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 96px;
  display: flex;
  justify-content: space-around;
  padding: 0 12px;
  pointer-events: none;
  overflow: hidden;
}
.lanterns::before {
  content: "";
  position: absolute;
  left: -5%; right: -5%; top: -40px;
  height: 70px;
  border-bottom: 2px solid rgba(40, 20, 10, 0.9);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.lantern {
  position: relative;
  margin-top: 22px;
  width: 40px;
  height: 52px;
  border-radius: 48% / 42%;
  display: grid;
  place-items: center;
  font-family: var(--mincho);
  font-weight: 800;
  font-size: 17px;
  color: #4a0a08;
  background:
    repeating-linear-gradient(to bottom, rgba(90, 13, 11, 0.22) 0 1px, transparent 1px 7px),
    radial-gradient(ellipse at 50% 45%, #fff3cc 0%, #ffb347 30%, #e2372b 66%, #8f1210 100%);
  box-shadow: 0 0 28px 8px rgba(255, 120, 40, 0.38);
  transform-origin: 50% -22px;
  animation: sway 4.2s ease-in-out infinite;
}
.lantern:nth-child(2n) { animation-duration: 5s; animation-delay: -1.3s; }
.lantern:nth-child(3n) { animation-duration: 4.6s; animation-delay: -2.1s; }
.lantern::before, .lantern::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 56%;
  height: 6px;
  transform: translateX(-50%);
  background: #1b120c;
  border-radius: 2px;
}
.lantern::before { top: -3px; }
.lantern::after { bottom: -3px; }
@keyframes sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}
@media (max-width: 640px) {
  .lantern:nth-child(n + 6) { display: none; }
}

/* ---- ヘッダー ---- */
.app-header {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  padding: 92px 16px 4px;
  text-align: center;
}
.app-header h1 {
  margin: 0;
  font-family: var(--mincho);
  font-weight: 800;
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  letter-spacing: 0.25em;
  padding-left: 0.25em;
  color: var(--kin-light);
  text-shadow: 0 0 18px rgba(255, 190, 90, 0.45), 0 2px 0 #5a3c10;
}
.header-actions {
  position: absolute;
  right: 16px;
  bottom: 10px;
  display: flex;
  gap: 8px;
}
@media (max-width: 860px) {
  .header-actions { position: static; justify-content: center; margin-top: 10px; }
}

.ghost-button {
  border: 1px solid rgba(243, 217, 138, 0.55);
  background: rgba(0, 0, 0, 0.28);
  color: var(--kinari);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}
.ghost-button:hover:not(:disabled) { background: rgba(243, 217, 138, 0.15); }
.ghost-button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- レイアウト ---- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* 漆塗りの舞台 */
.stage-card {
  background: linear-gradient(170deg, var(--urushi), var(--urushi-2));
  border: 2px solid var(--kin);
  border-radius: 14px;
  padding: 16px;
  box-shadow:
    inset 0 0 0 5px var(--urushi),
    inset 0 0 0 6px rgba(243, 217, 138, 0.45),
    0 18px 40px rgba(0, 0, 0, 0.45);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  padding: 9px 4px;
  border-radius: 7px;
  font-family: var(--mincho);
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--on-dark-muted);
  cursor: pointer;
}
.tab.is-active {
  background: linear-gradient(var(--shu-light), #a5161b);
  border-color: var(--kin);
  color: #fff6e0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.tab:disabled { cursor: not-allowed; }
@media (max-width: 480px) {
  .tab { letter-spacing: 0.02em; font-size: 0.92rem; }
}

.stage {
  position: relative;
  margin: 14px 0;
  height: min(470px, 92vw);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(212, 166, 64, 0.35);
  background:
    radial-gradient(ellipse 70% 55% at 50% 35%, rgba(255, 190, 110, 0.16), transparent 70%),
    #120a07;
}
.panel { position: absolute; inset: 0; display: none; }
.panel.is-active { display: block; }
.stage-canvas { width: 100%; height: 100%; display: block; }

/* 朱塗りの札のボタン */
.draw-button {
  display: block;
  width: 100%;
  border: 2px solid var(--kin);
  border-radius: 12px;
  padding: 14px;
  background: linear-gradient(var(--shu-light), #a5161b);
  color: #fff6e0;
  font-family: var(--mincho);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  box-shadow:
    0 5px 0 var(--shu-dark),
    0 10px 20px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.2s;
}
.draw-button:hover:not(:disabled) { filter: brightness(1.08); }
.draw-button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--shu-dark), 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.draw-button:disabled { filter: grayscale(0.6) brightness(0.7); cursor: not-allowed; }
.stage-note { min-height: 1.5em; margin: 10px 0 0; text-align: center; color: var(--on-dark-muted); }

/* ---- くじ箱 ---- */
.lottery {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 14px;
}
.box {
  position: relative;
  width: min(240px, 52%);
  aspect-ratio: 1 / 0.95;
  transform-origin: 50% 100%;
  perspective: 700px;
  z-index: 2;
  filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.55));
}
.box-top {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 22%;
  background:
    repeating-linear-gradient(92deg, rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 11px),
    linear-gradient(#b07a44, #7a4a22);
  border: 3px solid var(--kin);
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
}
.box-hole {
  width: 46%;
  height: 48%;
  background: radial-gradient(ellipse at 50% 30%, #2a160a, #050201 70%);
  border-radius: 50%;
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.8), 0 1px 0 rgba(255, 230, 180, 0.25);
}
.box-front {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  top: 22%;
  background:
    repeating-linear-gradient(97deg, rgba(0, 0, 0, 0.09) 0 2px, transparent 2px 9px, rgba(255, 220, 170, 0.05) 9px 11px, transparent 11px 17px),
    linear-gradient(165deg, #a3693a, #6b3c18);
  border: 3px solid var(--kin);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  box-shadow: inset 0 0 0 5px rgba(0, 0, 0, 0.12), inset 0 0 0 6px rgba(243, 217, 138, 0.35);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.box-label {
  font-family: var(--mincho);
  font-size: clamp(1.9rem, 8vw, 3.2rem);
  font-weight: 800;
  color: #f6e3a1;
  background: linear-gradient(#c62a2f, #8e1418);
  border: 2px solid var(--kin-light);
  padding: 0.05em 0.45em 0.05em 0.6em;
  border-radius: 6px;
  letter-spacing: 0.15em;
  text-shadow: 0 2px 0 #4a0a08;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35), inset 0 0 0 3px rgba(0, 0, 0, 0.15);
}
.box-count { margin: 12px 0 0; color: var(--on-dark-muted); font-size: 0.9rem; }

/* 和紙の短冊 */
.paper {
  position: absolute;
  left: 50%;
  top: 0;
  width: 40px;
  height: 70px;
  transform: translate(-50%, 90px); /* 最初は箱の中に隠れている */
  background:
    radial-gradient(circle at 20% 30%, rgba(160, 130, 80, 0.08) 0 1px, transparent 2px),
    radial-gradient(circle at 70% 60%, rgba(160, 130, 80, 0.08) 0 1px, transparent 2px),
    linear-gradient(#fdf9ef, #f1e8d2);
  background-size: 9px 11px, 13px 7px, auto;
  border: 1px solid #e0d2b0;
  border-radius: 3px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.3s ease, height 0.3s ease;
  z-index: 1;
}
.paper::before {
  content: "";
  position: absolute;
  inset: 8px 50%;
  border-left: 1px dashed #cdbd98;
}
.paper.is-open {
  width: min(280px, 78vw);
  height: 136px;
  z-index: 3;
  border-top: 7px solid var(--paper-color, var(--shu));
}
.paper.is-open::before { display: none; }
.paper-text {
  font-family: var(--mincho);
  font-size: 2rem;
  font-weight: 800;
  color: var(--ink);
  padding: 0 56px;
  text-align: center;
  overflow-wrap: anywhere;
}
.hanko {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: var(--mincho);
  font-size: 26px;
  font-weight: 800;
  color: #c9171e;
  border: 3px solid #c9171e;
  border-radius: 6px;
  background: rgba(201, 23, 30, 0.04);
  mix-blend-mode: multiply;
  opacity: 0;
  pointer-events: none;
}

/* ---- 項目（和紙のカード） ---- */
.items-card {
  color: var(--ink);
  background:
    radial-gradient(circle at 30% 20%, rgba(150, 120, 70, 0.06) 0 1px, transparent 2px),
    radial-gradient(circle at 80% 70%, rgba(150, 120, 70, 0.05) 0 1px, transparent 2px),
    var(--washi);
  background-size: 11px 13px, 17px 9px, auto;
  border: 1px solid #d8c9a8;
  border-radius: 10px;
  padding: 18px 16px;
  box-shadow: 0 0 0 3px rgba(212, 166, 64, 0.35), 0 18px 40px rgba(0, 0, 0, 0.4);
}
.items-card h2 {
  margin: 0 0 12px;
  font-family: var(--mincho);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.1em;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--shu);
}

.add-form { display: flex; gap: 8px; margin-bottom: 12px; }
.add-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #ddd0b0;
  border-radius: 8px;
  background: #fffaf0;
}
.add-form input:focus { outline: 2px solid var(--shu); outline-offset: -1px; }
.add-form button {
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--ink);
  color: var(--kinari);
  font-weight: 700;
  cursor: pointer;
}

.list-head, .item-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) 64px 56px 32px;
  gap: 8px;
  align-items: center;
}
.list-head {
  padding: 0 4px 6px;
  font-size: 0.78rem;
  color: var(--ink-muted);
  border-bottom: 1px solid #e0d3b5;
}
.list-head span:first-child { grid-column: 2; }

.item-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.item-row { padding: 6px 4px; border-bottom: 1px dashed #e0d3b5; }
.item-row input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fffaf0;
}
.item-row input:focus { outline: none; border-color: var(--shu); }
.swatch { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08); }
.item-prob { font-size: 0.85rem; color: var(--ink-muted); text-align: right; font-variant-numeric: tabular-nums; }
.icon-button {
  width: 32px; height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.icon-button:hover:not(:disabled) { background: rgba(201, 23, 30, 0.08); color: var(--shu); }
.item-row.is-won .item-name { text-decoration: line-through; opacity: 0.5; }
.item-row.is-won .swatch { opacity: 0.35; }
.empty { padding: 16px; text-align: center; color: var(--ink-muted); }

.options { margin-top: 16px; display: grid; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative;
  width: 44px; height: 26px;
  border-radius: 999px;
  background: #d6c9aa;
  transition: background 0.2s;
  flex: none;
}
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch input:checked + .switch-track { background: var(--shu); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--shu); outline-offset: 2px; }

.exclude-status { display: flex; align-items: center; justify-content: space-between; color: var(--ink-muted); font-size: 0.9rem; }
.exclude-status[hidden] { display: none; }
.items-card .ghost-button { border-color: #cdbd98; background: #fffaf0; color: var(--ink); }
.hint { margin: 14px 0 0; font-size: 0.8rem; color: var(--ink-muted); }

body.is-busy .items-card { opacity: 0.6; }

/* ---- 結果発表 ---- */
.reveal {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  background: transparent;
  color: var(--kinari);
  overflow: hidden;
  place-items: center;
}
.reveal[open] { display: grid; }
.reveal::backdrop { background: rgba(8, 5, 12, 0.8); }
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
.reveal-rays {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 170vmax;
  height: 170vmax;
  margin: -85vmax 0 0 -85vmax;
  background: repeating-conic-gradient(rgba(243, 217, 138, 0.2) 0deg 7deg, transparent 7deg 18deg);
  -webkit-mask: radial-gradient(circle, #000 0 12%, transparent 55%);
  mask: radial-gradient(circle, #000 0 12%, transparent 55%);
  animation: rays 24s linear infinite;
  pointer-events: none;
}
@keyframes rays { to { transform: rotate(360deg); } }

.plaque {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 32px));
  padding: 26px 22px 22px;
  text-align: center;
  background:
    repeating-linear-gradient(95deg, rgba(0, 0, 0, 0.08) 0 2px, transparent 2px 10px),
    linear-gradient(165deg, #a3693a, #5e3314);
  border: 4px solid var(--kin);
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 6px rgba(0, 0, 0, 0.15),
    inset 0 0 0 7px rgba(243, 217, 138, 0.5),
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 70px rgba(255, 200, 90, 0.35);
  animation: plaque-in 0.75s cubic-bezier(0.2, 1.3, 0.4, 1);
}
@keyframes plaque-in {
  from { transform: translateY(40px) scale(0.6) rotate(-4deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.reveal-title {
  margin: 0;
  font-family: var(--mincho);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.45em;
  padding-left: 0.45em;
  color: #f6e3a1;
  text-shadow: 0 2px 0 #3a1d08;
}
.reveal-title::before, .reveal-title::after { content: "―"; margin: 0 0.4em; opacity: 0.7; letter-spacing: 0; }
.result-name {
  margin: 14px 0 20px;
  padding: 0.35em 0.4em;
  font-family: var(--mincho);
  font-size: clamp(2.2rem, 9vw, 3.6rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--ink);
  background: linear-gradient(#fdf9ef, #efe5cc);
  border-left: 10px solid var(--result-color, var(--shu));
  border-right: 10px solid var(--result-color, var(--shu));
  border-radius: 4px;
  box-shadow: inset 0 0 18px rgba(120, 90, 40, 0.25), 0 4px 10px rgba(0, 0, 0, 0.3);
  overflow-wrap: anywhere;
  animation: name-in 0.6s 0.25s both cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes name-in {
  from { transform: scale(1.6); opacity: 0; filter: blur(4px); }
  to { transform: none; opacity: 1; filter: none; }
}

/* ---- お客様モード ---- */
.guest-exit { display: none; }
body.guest .guest-exit {
  display: block;
  position: fixed;
  top: 6px;
  right: 6px;
  z-index: 50;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  opacity: 0.12;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.guest-exit svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.guest-exit circle {
  fill: rgba(0, 0, 0, 0.35);
  stroke: var(--kin-light);
  stroke-width: 3;
  stroke-dasharray: 94.3;
  stroke-dashoffset: 94.3;
}
body.guest .guest-exit.is-holding { opacity: 1; }
.guest-exit.is-holding circle { stroke-dashoffset: 0; transition: stroke-dashoffset 1.5s linear; }

body.guest .items-card,
body.guest .tabs,
body.guest .header-actions,
body.guest .box-count { display: none; }
body.guest .layout { grid-template-columns: minmax(0, 1fr); max-width: 1300px; }
body.guest .stage { height: max(320px, calc(100vh - 330px)); margin-top: 0; }
body.guest .draw-button { font-size: 1.6rem; padding: 18px; }
