:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #171a21;
  --muted: #667085;
  --border: #e2e5ee;
  --accent: #5b5bf0;
  --accent-text: #ffffff;
  --danger: #d92d20;
  --ok: #12b76a;
  --warn: #f79009;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016;
    --surface: #171a23;
    --text: #eceef4;
    --muted: #98a2b3;
    --border: #272b38;
    --accent: #7c7cff;
    --accent-text: #0e1016;
    --danger: #f97066;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .05s ease, opacity .15s ease;
}
.btn:hover { opacity: .85; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Landing ---------- */
.landing {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  text-align: center;
}
.logo { font-size: 1.1rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: 28px; }
.logo span { color: var(--accent); }
.landing h1 { font-size: clamp(2rem, 6vw, 3.2rem); letter-spacing: -.03em; line-height: 1.1; margin: 0 0 14px; }
.landing p.lead { max-width: 520px; margin: 0 auto 28px; color: var(--muted); font-size: 1.1rem; }
.cta { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-bottom: 20px; }
.join { display: flex; gap: 8px; justify-content: center; margin-bottom: 44px; }
.join input {
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 240px;
  max-width: 100%;
  text-transform: lowercase;
}
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  max-width: 960px;
  width: 100%;
  text-align: left;
}
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.feature h3 { margin: 0 0 4px; font-size: 1rem; }
.feature p { margin: 0; color: var(--muted); font-size: .92rem; }
.err { color: var(--danger); min-height: 1.4em; font-size: .9rem; margin: -30px 0 28px; }

/* ---------- Session ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar .logo { margin: 0; text-decoration: none; color: var(--text); }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: .9rem;
}
.spacer { flex: 1; }
.status { display: flex; align-items: center; gap: 7px; font-size: .88rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.off { background: var(--danger); }

.editor { flex: 1; display: flex; padding: 12px 16px 16px; min-height: 160px; }
.editor textarea {
  flex: 1;
  width: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 18px 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  outline: none;
  tab-size: 4;
}
.editor textarea:focus { border-color: var(--accent); }

.footbar {
  display: flex;
  gap: 16px;
  padding: 8px 18px 12px;
  font-size: .82rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: all .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  padding: 20px; text-align: center;
}
.overlay .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 400px;
}
.overlay h2 { margin: 0 0 8px; }
.overlay p { color: var(--muted); margin: 0 0 20px; }
/* ---------- Landing: the two big buttons ---------- */
.bigbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 250px; padding: 16px 30px; border-radius: 14px;
  font: inherit; font-weight: 700; font-size: 1.05rem; line-height: 1.25;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  cursor: pointer; text-decoration: none; transition: transform .05s ease, opacity .15s ease;
}
.bigbtn small { font-weight: 500; font-size: .82rem; opacity: .8; }
.bigbtn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.bigbtn:hover { opacity: .9; }
.bigbtn:active { transform: translateY(1px); }
.bigbtn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 560px) { .bigbtn { width: 100%; } }

/* ---------- Validity picker (7 / 15 days) ---------- */
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 10px 12px; font-weight: 600; font-size: .92rem; white-space: nowrap;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.seg input:checked + span { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Save & share page ---------- */
.fvalue.ph { color: var(--muted); font-family: inherit; font-style: italic; }
.fcopy:disabled { opacity: .45; cursor: not-allowed; }
.editor textarea[readonly] { background: var(--surface); }
.bottombar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 4px 16px 16px; }
.bottombar .count { font-size: .85rem; color: var(--muted); }
.bbgroup { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.bbgroup .lbl { font-size: .88rem; color: var(--muted); }
.bbgroup .field { flex: 1 1 300px; }
.bottombar .seg label { flex: none; }
.bottombar .seg span { padding: 9px 16px; }
.bottombar .btn.primary { padding: 10px 28px; }
.berr { color: var(--danger); font-size: .88rem; }
.ok { color: var(--ok); font-weight: 700; font-size: .9rem; white-space: nowrap; }
@media (max-width: 640px) {
  .bottombar .spacer { display: none; }
  .bbgroup { width: 100%; }
  .bbgroup .lbl { flex: 0 0 100%; }
  .bbgroup .seg { flex: 1; }
  .bbgroup .seg label { flex: 1; }
}

/* ---------- Session: top bar extras ---------- */
.badge {
  font-size: .8rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; background: var(--bg); white-space: nowrap;
}
.badge.soon { color: var(--warn); border-color: var(--warn); }
.endwrap { display: inline-flex; align-items: center; gap: 8px; }
.confirm-text { font-size: .9rem; color: var(--danger); font-weight: 600; }
.btn.solid { background: var(--danger); color: #fff; border-color: transparent; }

/* ---------- Session: share fields (value + Copy at the end) ---------- */
.sharebar { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 16px 0; }
#shareInfo { padding: 0 16px 12px; }
.field {
  display: flex; align-items: stretch; min-width: 0; max-width: 100%;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); overflow: hidden;
}
.sharebar .field { width: fit-content; }
.flabel { min-width: 104px; }
.flabel {
  display: flex; align-items: center; padding: 0 10px;
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); background: var(--bg); border-right: 1px solid var(--border);
  white-space: nowrap;
}
.fvalue {
  flex: 0 1 auto; min-width: 0; align-self: center; padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fcopy {
  appearance: none; border: 0; border-left: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; font-weight: 600; padding: 0 16px; cursor: pointer;
  min-width: 92px;
}
#vShare, #vOwner { color: var(--accent); }
.fcopy:hover { background: var(--bg); }
.fcopy.done { color: var(--ok); }

@media (max-width: 640px) {
  .flabel { min-width: 84px; }
  .topbar { gap: 8px; }
}

[hidden] { display: none !important; }
