:root {
  --bg: #140a0c;
  --wood: #3a2216;
  --wood-dark: #24140d;
  --neon: #ff4fa3;
  --neon-glow: rgba(255, 79, 163, .55);
  --amber: #ffb547;
  --amber-glow: rgba(255, 181, 71, .45);
  --text: #f7e9dc;
  --muted: #b89c8a;
  --danger: #e5484d;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 150, 80, .18), transparent 60%),
    radial-gradient(ellipse at 90% 110%, rgba(255, 79, 163, .10), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: 'Zen Kaku Gothic New', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
[hidden] { display: none !important; }

.screen { min-height: 100dvh; }

/* ---------- 入口 ---------- */
#entrance, #outside { display: grid; place-items: center; padding: 24px 16px; }
.door {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, var(--wood), var(--wood-dark));
  border: 1px solid rgba(255, 200, 150, .12);
  border-radius: 20px 20px 10px 10px;
  padding: 32px 22px 26px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 220, 180, .08);
  text-align: center;
}
.sign {
  display: inline-flex; flex-direction: column; align-items: center;
  padding: 14px 26px 10px;
  border: 2px solid var(--neon); border-radius: 12px;
  box-shadow: 0 0 12px var(--neon-glow), inset 0 0 12px var(--neon-glow);
  font-family: 'Yusei Magic', sans-serif;
  color: #ffd9ec;
  text-shadow: 0 0 6px var(--neon), 0 0 18px var(--neon), 0 0 36px var(--neon-glow);
  animation: flicker 6s infinite;
}
.door .sign { cursor: pointer; }
.sign-small { font-size: 15px; letter-spacing: .4em; margin-right: -.4em; }
.sign-big { font-size: 52px; line-height: 1.1; letter-spacing: .1em; }
.sign.dim { animation: none; opacity: .35; text-shadow: none; box-shadow: none; }
@keyframes flicker {
  0%, 92%, 95%, 100% { opacity: 1; }
  93% { opacity: .55; }
  94% { opacity: .9; }
  96% { opacity: .7; }
}
.hours { color: var(--amber); font-size: 13px; margin: 14px 0 22px; min-height: 1em; }

#join-form { display: grid; gap: 14px; text-align: left; }
#join-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
#join-form input {
  width: 100%; padding: 12px 14px;
  background: rgba(0, 0, 0, .35); color: var(--text);
  border: 1px solid rgba(255, 200, 150, .18); border-radius: 10px;
  font-size: 16px; /* iOSのズーム防止 */
}
#join-form input:focus { outline: 2px solid var(--amber); outline-offset: 1px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 68px !important; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 12px;
  border: 1px solid rgba(255, 200, 150, .25); background: rgba(255, 255, 255, .06); color: var(--muted);
}
.field-label { font-size: 13px; color: var(--muted); }
.field-label small { font-size: 11px; margin-left: 4px; opacity: .8; }
.drink-field { display: grid; gap: 6px; }
.drinks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.drink {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px; border-radius: 10px; cursor: pointer;
  border: 1px solid rgba(255, 200, 150, .18); background: rgba(0, 0, 0, .25); color: var(--muted); font-size: 11px;
}
.drink .d-ico { font-size: 22px; line-height: 1.1; }
.drink.on { border-color: var(--amber); background: rgba(255, 181, 71, .16); color: var(--amber); }
.toggles { display: flex; gap: 8px; }
.chip {
  flex: 1; padding: 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(255, 200, 150, .25); background: transparent; color: var(--muted);
}
.chip.on { background: rgba(255, 181, 71, .16); color: var(--amber); border-color: var(--amber); }
.hint { margin: -4px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.enter-btn {
  margin-top: 4px; padding: 14px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(180deg, #ffc56b, #f09a2c); color: #2a1408;
  font-weight: 700; font-size: 17px; letter-spacing: .1em;
  box-shadow: 0 6px 20px var(--amber-glow);
}
.enter-btn:disabled { opacity: .6; cursor: wait; }
.error { color: #ff8f94; font-size: 13px; text-align: center; min-height: 1em; margin: 0; }
.farewell { margin: 24px 0; color: var(--muted); }

/* ---------- 店内 ---------- */
#bar { display: flex; flex-direction: column; height: 100dvh; }
.bar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.mini-sign {
  font-family: 'Yusei Magic', sans-serif; font-size: 13px; color: #ffd9ec;
  text-shadow: 0 0 6px var(--neon), 0 0 14px var(--neon-glow);
}
.mini-sign b { font-size: 22px; font-weight: 400; margin-left: 4px; }
.head-right { display: flex; align-items: center; gap: 12px; }
.count { font-size: 13px; color: var(--muted); }
.leave-btn {
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 12px;
  border: 1px solid rgba(255, 200, 150, .25); background: transparent; color: var(--muted);
}
@media (max-width: 520px) { .count { display: none; } }

.stage { flex: 1; display: flex; min-height: 0; }
.counter {
  flex: 1; overflow-y: auto;
  display: grid; gap: 8px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  padding: 8px 16px 16px;
}
@media (max-width: 520px) {
  .counter { grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 6px 10px 12px; }
}
@media (min-width: 1000px) {
  .counter { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}

.tile {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #2c1a12, #1a0e0a);
  border: 2px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
/* 話している人を大きく（2列×2段ぶん） */
.tile.featured { grid-column: span 2; grid-row: span 2; }
@media (max-width: 520px) { .tile.featured { grid-row: span 1; aspect-ratio: 16 / 10; } }
.tile.featured .avatar span { width: 88px; height: 88px; font-size: 38px; }
.tile.featured .nameplate { font-size: 14px; }
.tile.speaking { border-color: var(--amber); box-shadow: 0 0 18px var(--amber-glow); }
.tile.mama { background: linear-gradient(160deg, #3b1428, #1e0a14); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.self video { transform: scaleX(-1); }
.avatar {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.avatar span {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 181, 71, .18); color: var(--amber);
  font-size: 24px; font-weight: 700;
}
.tile.mama .avatar span { background: rgba(255, 79, 163, .2); color: #ff9fcc; }
.nameplate {
  position: absolute; left: 6px; bottom: 6px; right: 6px;
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; pointer-events: none;
}
.nameplate .n {
  background: rgba(0, 0, 0, .6); padding: 3px 8px; border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.nameplate .muted-ico { flex-shrink: 0; white-space: nowrap; background: rgba(229, 72, 77, .85); border-radius: 999px; padding: 2px 6px; font-size: 11px; }
.mama-badge {
  position: absolute; top: 6px; left: 6px;
  background: var(--neon); color: #fff; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; box-shadow: 0 0 10px var(--neon-glow);
}
.tile-actions {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 4px;
}
.tile-actions button {
  border: 0; border-radius: 8px; padding: 4px 8px; font-size: 11px; cursor: pointer;
  background: rgba(0, 0, 0, .65); color: var(--text);
}
.tile-actions button.kick { background: rgba(229, 72, 77, .85); }

/* チャット */
.chat {
  display: flex; flex-direction: column;
  width: 320px; flex-shrink: 0; margin: 8px 16px 16px 0;
  background: rgba(20, 10, 8, .85); border: 1px solid rgba(255, 200, 150, .15);
  border-radius: var(--radius); overflow: hidden;
}
.chat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid rgba(255, 200, 150, .1);
}
.chat-close { border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 8px; }
.chat-log { flex: 1; overflow-y: auto; margin: 0; padding: 10px 12px; list-style: none; display: grid; gap: 8px; align-content: start; }
.chat-note { font-size: 11px; color: var(--muted); text-align: center; opacity: .7; }
.msg { display: grid; gap: 2px; justify-items: start; }
.msg .who { font-size: 11px; color: var(--muted); }
.msg .who time { margin-left: 6px; opacity: .6; }
.msg .body {
  background: rgba(255, 255, 255, .07); padding: 7px 11px; border-radius: 4px 14px 14px 14px;
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-width: 100%;
}
.msg.mine { justify-items: end; }
.msg.mine .body { background: rgba(255, 181, 71, .2); border-radius: 14px 4px 14px 14px; }
.msg.mama .who { color: #ff9fcc; }
.msg.mama .body { background: rgba(255, 79, 163, .18); }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid rgba(255, 200, 150, .1); }
.chat-form input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 999px;
  border: 1px solid rgba(255, 200, 150, .2); background: rgba(0, 0, 0, .35); color: var(--text);
  font-size: 16px; /* iOSのズーム防止 */
}
.chat-form input:focus { outline: 2px solid var(--amber); outline-offset: 0; }
.chat-send {
  padding: 0 14px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--amber); color: #2a1408; font-weight: 700;
}
.ctl { position: relative; }
.ctl.active { border-color: var(--amber); color: var(--amber); }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: var(--neon); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 0 8px var(--neon-glow);
}
@media (max-width: 760px) {
  .chat {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    width: auto; height: 62dvh; margin: 0;
    border-radius: 18px 18px 0 0; background: #180c09;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -20px 50px rgba(0, 0, 0, .6);
  }
}

.order-sheet {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 26;
  width: min(92vw, 360px); padding: 12px;
  background: #24140d; border: 1px solid var(--amber); border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .6);
}
.order-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; }
.nameplate .drink-ico { flex-shrink: 0; font-size: 15px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.8)); }

.reactions {
  display: flex; justify-content: center; gap: 8px; padding: 6px 16px 8px;
}
.reactions button {
  width: 44px; height: 38px; border-radius: 999px; cursor: pointer; font-size: 20px; line-height: 1;
  border: 1px solid rgba(255, 200, 150, .15); background: rgba(0, 0, 0, .3);
  transition: transform .1s;
}
.reactions button:active { transform: scale(1.25); }
.reactions .call-mama {
  width: auto; padding: 0 12px; font-size: 13px; color: #ffd9ec;
  border-color: rgba(255, 79, 163, .5); background: rgba(255, 79, 163, .12);
}
.tile.calling { border-color: var(--neon); animation: calling 1s ease-in-out infinite; }
@keyframes calling { 50% { box-shadow: 0 0 24px var(--neon-glow); } }
.react-fly {
  position: fixed; z-index: 16; pointer-events: none; font-size: 34px;
  animation: react-up 1.8s ease-out forwards;
}
@keyframes react-up {
  0% { transform: translate(-50%, 0) scale(.5); opacity: 0; }
  15% { transform: translate(-50%, -20px) scale(1.2); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), -180px) scale(1); opacity: 0; }
}

.controls {
  display: flex; justify-content: center; gap: 6px;
  padding: 10px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, var(--wood-dark), var(--wood));
  border-top: 1px solid rgba(255, 200, 150, .12);
}
.ctl {
  display: grid; justify-items: center; gap: 2px;
  min-width: 58px; padding: 8px 8px; border-radius: 12px; cursor: pointer;
  background: rgba(0, 0, 0, .3); color: var(--text);
  border: 1px solid rgba(255, 200, 150, .15); font-size: 11px;
}
.ctl .ico { font-size: 22px; line-height: 1; }
.ctl .st { font-size: 10px; font-weight: 700; letter-spacing: .08em; padding: 1px 8px; border-radius: 999px; }
.ctl.live { border-color: rgba(92, 214, 140, .6); }
.ctl.live .st { background: #2f9e62; color: #fff; }
.ctl.off .st { background: var(--danger); color: #fff; }
.ctl.off { background: rgba(229, 72, 77, .25); border-color: var(--danger); color: #ffb3b6; }
.ctl.off .ico { opacity: .85; }
.ctl.cheers { background: rgba(255, 181, 71, .18); border-color: var(--amber); color: var(--amber); }

.mama-panel {
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; background: rgba(255, 79, 163, .08);
  border-top: 1px solid rgba(255, 79, 163, .25);
}
.mama-label { color: #ff9fcc; font-size: 12px; font-weight: 700; }
.btn-small {
  border: 1px solid rgba(255, 200, 150, .25); background: rgba(0, 0, 0, .3); color: var(--text);
  padding: 6px 12px; border-radius: 8px; font-size: 12px; cursor: pointer;
}
.btn-small.danger { border-color: var(--danger); color: #ffb3b6; }

.start-audio {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  padding: 12px 20px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--amber); color: #2a1408; font-weight: 700; z-index: 30;
}

.reconnecting {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: #8a5a12; color: #fff; text-align: center; font-size: 14px; font-weight: 700;
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: .75; } }

/* 通知 */
#toasts {
  position: fixed; top: max(56px, calc(env(safe-area-inset-top) + 46px)); left: 50%;
  transform: translateX(-50%); display: grid; gap: 6px; z-index: 20;
  width: min(92vw, 360px); pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: 999px; text-align: center; font-size: 14px;
  background: rgba(36, 20, 13, .92); border: 1px solid var(--amber); color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  animation: toast-in .3s ease-out, toast-out .4s ease-in 3.2s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* 乾杯演出 */
#cheers-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 15; }
.glass {
  position: absolute; bottom: -60px; font-size: 42px;
  animation: rise 2.6s cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes rise {
  0% { transform: translateY(0) rotate(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-85vh) rotate(var(--r)); opacity: 0; }
}
.cheers-banner {
  position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%);
  font-family: 'Yusei Magic', sans-serif; font-size: clamp(40px, 12vw, 88px);
  color: #fff3c4; text-shadow: 0 0 10px var(--amber), 0 0 30px var(--amber-glow);
  animation: pop 1.6s ease-out forwards; white-space: nowrap;
}
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -60%) scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sign { animation: none; }
  .glass { animation-duration: .01s; }
}
