:root {
  --bg: #f4efe8;
  --ink: #102a43;
  --ink-soft: #486581;
  --surface: #fffdf9;
  --line: #d9cfc1;
  --primary: #0f766e;
  --accent: #d92d20;
  --danger: #b42318;
  --shadow: 0 10px 24px rgba(16, 42, 67, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 12%, #f8dcbf 0%, transparent 40%),
    radial-gradient(circle at 86% 24%, #c5e9e4 0%, transparent 35%),
    var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', 'Noto Sans KR', sans-serif;
  padding: 20px;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.hero {
  position: relative;
}

.hub-link {
  position: absolute;
  top: 14px;
  right: 16px;
  color: rgba(16, 42, 67, 0.34);
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hub-link:hover {
  color: rgba(16, 42, 67, 0.7);
}

.hero h1 {
  margin: 6px 0;
  font-size: clamp(30px, 6vw, 46px);
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.subtitle {
  margin: 0;
  color: var(--ink-soft);
}

.lobby-actions {
  display: flex;
  gap: 10px;
  margin: 12px 0;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #f4fffd;
  border-color: transparent;
}

.btn-accent {
  background: var(--accent);
  color: #fff5f4;
  border-color: transparent;
}

.btn-danger {
  border-color: #e9b3ad;
  color: var(--danger);
  background: #fff5f4;
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.room-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  background: #fff;
}

.room-item:hover {
  border-color: #87c7be;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.topbar h2 {
  margin: 0;
}

#stateBadge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #e5f3f1;
  border: 1px solid #b9dfd9;
  font-size: 13px;
}

.top-controls {
  display: flex;
  gap: 8px;
}

.room-layout {
  display: grid;
  grid-template-columns: 260px 1fr 300px;
  gap: 12px;
  align-items: start;
}

.side-left,
.side-right {
  height: 520px;
  min-height: 520px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.center-stage {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.side-left {
  align-self: start;
}

.center-stage {
  align-self: start;
}

.side-right {
  align-self: start;
}

.player-list {
  flex: 1;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.player-item {
  border-bottom: 1px solid #e7edf3;
  padding: 8px 0;
}

.player-item strong {
  display: block;
  margin-bottom: 4px;
}

.player-meta {
  color: var(--ink-soft);
  font-size: 13px;
}

.host-controls {
  margin-top: 14px;
  display: grid;
  gap: 6px;
  flex-shrink: 0;
}

label {
  font-size: 13px;
  color: var(--ink-soft);
}

input {
  width: 100%;
  border: 1px solid #b6c4d2;
  border-radius: 10px;
  padding: 9px 10px;
}

.center-stage h3 {
  margin-top: 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.turn-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-row p {
  margin: 0;
  font-weight: 700;
}

#bellInfo {
  margin: 8px 0;
  color: var(--ink-soft);
}

.action-row {
  display: flex;
  gap: 8px;
  margin: 10px 0;
  min-height: 44px;
  align-items: center;
  flex-shrink: 0;
}

.bell-zone {
  position: relative;
  width: 100%;
  min-height: 120px;
  border: 1px dashed #c8d7e8;
  border-radius: 12px;
  background: #f8fbff;
  overflow: hidden;
  flex-shrink: 0;
}

.bell-floating-btn {
  position: absolute;
  left: 10px;
  top: 10px;
}

.open-cards {
  min-height: 220px;
  display: grid;
  grid-template-columns: repeat(auto-fill, 140px);
  justify-content: center;
  gap: 12px;
  align-content: start;
  overflow-x: hidden;
}

.open-slot {
  width: 140px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.open-slot img {
  width: 100%;
  height: 186px;
  object-fit: contain;
  display: block;
  border: none;
  border-radius: 0;
}

.open-slot.is-turn-player p {
  color: #b42318;
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.open-slot-card {
  position: relative;
  display: inline-block;
  perspective: 900px;
}

.open-slot-front {
  max-width: 100%;
  height: auto;
  display: block;
}

.open-slot-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  backface-visibility: hidden;
  transform-origin: center;
  opacity: 0;
  pointer-events: none;
}

.open-slot-card.is-flipping .open-slot-cover {
  opacity: 1;
  animation: coverFlipAway 520ms ease forwards;
}

@keyframes coverFlipAway {
  0% {
    transform: rotateY(0deg);
    opacity: 1;
  }
  60% {
    transform: rotateY(72deg);
    opacity: 1;
  }
  100% {
    transform: rotateY(90deg);
    opacity: 0;
  }
}

.open-slot p {
  margin: 8px 0 0;
  font-size: 13px;
  text-align: center;
  font-weight: 600;
  width: 100%;
  min-height: 20px;
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chatList {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 10px;
  list-style: none;
  border: 1px solid #d8e2ec;
  border-radius: 10px;
  background: #f3f6fb;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#chatList li {
  margin: 0;
}

.chat-panel #chatInput {
  margin-top: 2px;
}

.chat-panel #chatSendBtn {
  margin-top: 2px;
}

.chat-item {
  max-width: 84%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-item.mine {
  align-self: flex-end;
}

.chat-item.other {
  align-self: flex-start;
}

.chat-name {
  font-size: 11px;
  color: #5f7d95;
  padding: 0 2px;
}

.chat-bubble {
  border-radius: 14px;
  padding: 8px 11px;
  line-height: 1.35;
  word-break: break-word;
}

.chat-item.other .chat-bubble {
  background: #ffffff;
  border: 1px solid #d6e3ef;
  box-shadow: 0 2px 4px rgba(16, 42, 67, 0.08);
}

.chat-item.mine .chat-bubble {
  background: #dff3ff;
  border: 1px solid #9bc8ea;
  box-shadow: 0 2px 4px rgba(30, 72, 114, 0.1);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 20, 40, 0.42);
}

.modal-panel {
  position: relative;
  z-index: 31;
  width: min(92vw, 420px);
  margin: 10vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  margin: 0 0 8px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.muted {
  color: var(--ink-soft);
  font-size: 13px;
}

.bell-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.bell-overlay-card {
  min-width: 260px;
  max-width: 82vw;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 20px;
  padding: 18px 20px 16px;
  box-shadow: 0 18px 40px rgba(16, 42, 67, 0.34);
  text-align: center;
  border: 2px solid #d8e2ec;
}

.bell-overlay-card.success {
  border-color: #0f766e;
}

.bell-overlay-card.fail {
  border-color: #b42318;
}

.bell-icon-wrap {
  width: 76px;
  height: 76px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f7fb;
}

.bell-overlay-card.success .bell-icon-wrap {
  background: #d9f4ef;
}

.bell-overlay-card.fail .bell-icon-wrap {
  background: #fde7e5;
}

.bell-icon {
  font-size: 40px;
  line-height: 1;
}

.bell-overlay-text {
  margin: 0;
  font-weight: 700;
  font-size: 18px;
  color: #153a5b;
}

.my-turn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: #d92d20;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #b42318;
}

@media (max-width: 980px) {
  .room-layout {
    grid-template-columns: 1fr;
  }

  .side-left,
  .center-stage,
  .side-right {
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .open-cards {
    grid-template-columns: repeat(auto-fill, 120px);
    gap: 10px;
  }

  .open-slot {
    width: 120px;
  }

  .open-slot img {
    height: 160px;
  }
}
