:root {
  --ink: #060b16;
  --surface: rgba(12, 20, 38, 0.92);
  --surface-2: rgba(255, 255, 255, 0.04);
  --line: rgba(246, 239, 226, 0.12);
  --line-strong: rgba(243, 212, 151, 0.45);
  --champagne: #f6efe2;
  --gold: #f3d497;
  --gold-deep: #dda859;
  --text: #f5f2eb;
  --text-2: #b9c3d4;
  --text-3: #7e8ba1;
  --danger: #f87171;
  --ok: #86efac;
  --font: 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse at 50% -10%, rgba(243, 212, 151, 0.1), transparent 55%),
    linear-gradient(180deg, #060b16 0%, #0a1426 60%, #050a14 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font-family: var(--font); }
.is-hidden { display: none !important; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 1.5px solid var(--gold);
  outline-offset: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 400;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.btn:hover { border-color: var(--line-strong); background: rgba(243, 212, 151, 0.1); transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  border-color: rgba(255, 245, 220, 0.6);
  background: linear-gradient(180deg, #f5d89e 0%, #dda859 100%);
  color: #181106;
  font-weight: 500;
}
.btn-primary:hover { background: linear-gradient(180deg, #f8e0ae 0%, #e4b169 100%); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.78rem; }
.btn-danger:hover { border-color: rgba(248, 113, 113, 0.55); background: rgba(248, 113, 113, 0.1); color: #fca5a5; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 0.78rem; color: var(--text-2); }
.field input {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(5, 10, 20, 0.65);
  color: var(--text);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(243, 212, 151, 0.14); }
.form-error { min-height: 1.1em; font-size: 0.78rem; color: #fca5a5; }
.form-note { margin-top: 10px; min-height: 1.1em; font-size: 0.8rem; color: var(--ok); }
.form-note.is-error { color: #fca5a5; }

/* Login */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
}
.login-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 26px 24px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.login-mark {
  width: 52px; height: 52px; margin: 0 auto 2px;
  display: grid; place-items: center; border-radius: 50%;
  background: rgba(243, 212, 151, 0.08); border: 1px solid rgba(243, 212, 151, 0.28);
}
.login-mark svg { width: 28px; height: 28px; }
.login-card h1 { font-size: 1.3rem; font-weight: 500; text-align: center; color: var(--champagne); }
.login-sub { text-align: center; font-size: 0.82rem; font-weight: 300; color: var(--text-3); margin-bottom: 6px; }
.back-link { text-align: center; font-size: 0.78rem; color: var(--text-3); text-decoration: none; margin-top: 2px; }
.back-link:hover { color: var(--gold); }

/* Dashboard */
.dash-view { max-width: 1040px; margin: 0 auto; padding: calc(20px + var(--safe-top)) 20px calc(40px + var(--safe-bottom)); }
.dash-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.dash-title h1 { font-size: clamp(1.25rem, 3vw, 1.6rem); font-weight: 500; color: var(--champagne); }
.dash-title p { font-size: 0.82rem; font-weight: 300; color: var(--text-3); margin-top: 2px; }
.dash-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dash-main { display: flex; flex-direction: column; gap: 18px; }

.panel {
  padding: 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.panel h2 { font-size: 1rem; font-weight: 500; color: var(--champagne); margin-bottom: 14px; }

.create-form { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.field-grow { flex: 1 1 220px; }
.field-count { width: 96px; }

.seg { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.seg-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 6px 14px; min-width: 128px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
  text-align: left; transition: all 0.18s ease;
}
.seg-btn strong { font-size: 0.84rem; font-weight: 500; }
.seg-btn small { font-size: 0.68rem; font-weight: 300; color: var(--text-3); }
.seg-btn.active { background: rgba(243, 212, 151, 0.14); border-color: rgba(243, 212, 151, 0.4); color: var(--champagne); }
.seg-btn.active small { color: var(--gold); }

/* Room list */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.list-head h2 { margin: 0; }
.filter { display: flex; gap: 6px; }
.filter-btn {
  min-height: 32px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
  font-size: 0.78rem; cursor: pointer; transition: all 0.16s ease;
}
.filter-btn.active { background: rgba(243, 212, 151, 0.14); border-color: var(--gold); color: var(--champagne); }

.room-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 12px; }
.room-card {
  display: flex; flex-direction: column; gap: 12px; padding: 16px;
  border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line);
}
.room-card.is-closed { opacity: 0.78; }
.room-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.room-name { font-size: 1rem; font-weight: 500; color: var(--champagne); overflow-wrap: anywhere; }
.room-meta { font-size: 0.74rem; font-weight: 300; color: var(--text-3); margin-top: 2px; }
.code-badge {
  flex-shrink: 0; padding: 4px 11px; border-radius: 10px;
  background: rgba(243, 212, 151, 0.1); border: 1px dashed rgba(243, 212, 151, 0.45);
  color: var(--gold); font-size: 0.95rem; font-weight: 600; letter-spacing: 0.14em;
}
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { padding: 2px 10px; border-radius: 999px; font-size: 0.7rem; border: 1px solid var(--line); color: var(--text-2); }
.badge-open { color: var(--ok); border-color: rgba(134, 239, 172, 0.35); }
.badge-closed { color: #fca5a5; border-color: rgba(248, 113, 113, 0.35); }

.slot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.slot-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  min-height: 36px; padding: 4px 6px 4px 11px; border-radius: 10px;
  border: 1px solid var(--line); font-size: 0.78rem; min-width: 0;
}
.slot-chip.is-empty { color: var(--text-3); border-style: dashed; }
.slot-chip.is-filled { color: var(--champagne); background: rgba(243, 212, 151, 0.07); border-color: rgba(243, 212, 151, 0.25); }
.slot-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-clear {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; color: var(--text-3);
  font-size: 0.9rem; line-height: 1; cursor: pointer;
}
.slot-clear:hover { color: #fca5a5; border-color: rgba(248, 113, 113, 0.5); }

.link-row { display: flex; gap: 6px; }
.link-row input {
  flex: 1; min-width: 0; min-height: 34px; padding: 0 11px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(5, 10, 20, 0.55); color: var(--gold); font-size: 0.74rem;
}
.room-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.empty-state { text-align: center; padding: 28px 12px; font-size: 0.86rem; color: var(--text-3); }

.dev-credit {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--text-3);
  opacity: 0.72;
}
.dash-credit { margin-top: 24px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-bottom)); z-index: 50;
  transform: translate(-50%, 14px); max-width: calc(100vw - 32px);
  padding: 10px 18px; border-radius: 999px; background: rgba(10, 18, 34, 0.96);
  border: 1px solid rgba(243, 212, 151, 0.4); color: var(--champagne); font-size: 0.82rem; text-align: center;
  opacity: 0; visibility: hidden; pointer-events: none; transition: all 0.24s ease;
}
.toast.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .dash-view { padding-left: 14px; padding-right: 14px; }
  .panel { padding: 16px; border-radius: 18px; }
  .create-form { flex-direction: column; align-items: stretch; }
  .field-count { width: 100%; }
  .seg { flex-direction: column; }
  .seg-btn { width: 100%; }
  .create-form .btn { width: 100%; }
  .room-list { grid-template-columns: 1fr; }
  .dash-header-actions { width: 100%; }
  .dash-header-actions .btn { flex: 1; }
  .field input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
