/* Squire — Main Stylesheet (Light Theme) */

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

:root {
  --bg-dark: #f5f3ef;
  --bg-card: #ffffff;
  --bg-input: #faf9f7;
  --bg-hover: #f0ece4;
  --border: #d5cfc5;
  --border-light: #b0a690;
  --text: #3a3530;
  --text-dim: #8a7a60;
  --text-bright: #2a2520;
  --accent: #7a6530;
  --accent-hover: #5a4a20;
  --accent-dim: #a08a50;
  --danger: #b54a4a;
  --danger-bg: #fdf0f0;
  --success: #2d7a45;
  --success-bg: #e8f5ec;
  --mode-plan: #4a7abf;
  --mode-play: #3a9a5a;
  --radius: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 70px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.sq-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

.sq-page--narrow {
  max-width: 440px;
}

/* ── Header / Nav ────────────────────────────────────────────────────────── */

.sq-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.sq-header__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.sq-header__nav {
  display: flex;
  align-items: baseline;
  gap: 16px;
  font-size: 0.8125rem;
}

.sq-header__user {
  color: var(--text-dim);
}

.sq-header__user .sq-badge {
  vertical-align: baseline;
  position: relative;
  top: -1px;
}

.sq-header__link {
  color: var(--text-dim);
  transition: color 0.15s;
}

.sq-header__link:hover {
  color: var(--text-bright);
}

/* ── Cards ───────────────────────────────────────────────────────────────── */

.sq-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.sq-card__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.sq-card + .sq-card {
  margin-top: 16px;
}

.sq-grid > .sq-card + .sq-card {
  margin-top: 0;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

.sq-form { display: flex; flex-direction: column; gap: 14px; }

.sq-field { display: flex; flex-direction: column; gap: 4px; }
.sq-field-hint { font-size: 0.6875rem; color: var(--text-dim); font-style: italic; }

.sq-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sq-input, .sq-select, .sq-textarea {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 0.875rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.sq-input:focus, .sq-select:focus, .sq-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.sq-input::placeholder, .sq-textarea::placeholder {
  color: var(--border-light);
}

.sq-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a7a60'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.sq-textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.sq-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.sq-btn--primary {
  background: var(--accent);
  color: #fff;
}

.sq-btn--primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.sq-btn--secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.sq-btn--secondary:hover {
  border-color: var(--accent-dim);
  color: var(--text-bright);
}

.sq-btn--danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.sq-btn--danger:hover {
  background: var(--danger);
  color: #fff;
}

.sq-btn--small {
  padding: 6px 14px;
  font-size: 0.75rem;
}

.sq-btn--full {
  width: 100%;
}

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

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.sq-alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

.sq-alert--error {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: #a03030;
}

.sq-alert--success {
  background: var(--success-bg);
  border: 1px solid var(--success);
  color: #1a6030;
}

.sq-alert:empty { display: none; }

/* ── Auth Page ───────────────────────────────────────────────────────────── */

.sq-auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.sq-auth__logo {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.sq-auth__subtitle {
  color: var(--text-dim);
  font-size: 0.8125rem;
  margin-bottom: 32px;
}

.sq-auth__card {
  width: 100%;
  max-width: 400px;
}

.sq-auth__toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 0.8125rem;
  color: var(--text-dim);
}

.sq-auth__toggle a {
  font-weight: 600;
}

/* ── Tabs (auth mode switcher) ───────────────────────────────────────────── */

.sq-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
}

.sq-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: transparent;
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}

.sq-tab:first-child { border-radius: var(--radius) 0 0 0; }
.sq-tab:last-child { border-radius: 0 var(--radius) 0 0; }

.sq-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sq-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-card);
}

/* ── Dashboard ───────────────────────────────────────────────────────────── */

.sq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.sq-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.sq-empty__icon {
  font-size: 2.25rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */

.sq-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.sq-badge--dm {
  background: #f3ecf8;
  color: #7a50a0;
  border: 1px solid #d0b8e0;
}

.sq-badge--player {
  background: #e8f0f5;
  color: #3a7a90;
  border: 1px solid #a0c8d8;
}

.sq-badge--npc {
  background: #f5f0e8;
  color: #8a6a20;
  border: 1px solid #d0b870;
}

.sq-badge--homebrew {
  background: #edf5e8;
  color: #3a7a30;
  border: 1px solid #a0c890;
  vertical-align: middle;
}

/* ── Segmented Toggle (slider-style selector) ────────────────────────────── */
/* Usage: <div class="sq-seg-toggle"><div class="sq-seg-toggle__slider"></div>
          <button class="sq-seg-toggle__opt is-active">A</button>
          <button class="sq-seg-toggle__opt">B</button></div>
   JS: call sqSegToggleInit(el) to wire up click → slide behaviour.      */

.sq-seg-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.sq-seg-toggle__slider {
  position: absolute;
  top: 2px;
  height: calc(100% - 4px);
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: left 0.2s ease, width 0.2s ease;
  pointer-events: none;
  z-index: 0;
}

.sq-seg-toggle__opt {
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 16px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.sq-seg-toggle__opt.is-active { color: var(--text-bright); }

/* Icon-only variant */
.sq-seg-toggle--icons .sq-seg-toggle__opt { padding: 3px 6px; }
.sq-seg-toggle--icons .sq-seg-toggle__opt svg { display: block; }

/* ── Utility ─────────────────────────────────────────────────────────────── */

.sq-mt-sm { margin-top: 8px; }
.sq-mt { margin-top: 16px; }
.sq-mt-lg { margin-top: 24px; }
.sq-text-center { text-align: center; }
.sq-text-dim { color: var(--text-dim); }
.sq-text-sm { font-size: 0.75rem; }
.sq-hidden { display: none !important; }
.sq-flex { display: flex; }

/* ── Character Edit Overlay ─────────────────────────────────────────────── */
.char-edit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.char-edit-overlay.sq-hidden { display: none !important; }
.char-edit-overlay__inner {
  position: relative;
  width: 92vw;
  max-width: 780px;
  height: 90vh;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius, 6px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.char-edit-overlay__close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.375rem;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  z-index: 1;
  padding: 0 4px;
}
.char-edit-overlay__close:hover { color: var(--accent); }
.char-edit-overlay__iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}
/* ── Standalone Level Editor ─────────────────────────────────────────────── */
.sq-level-editor {
  position: fixed; inset: 0; z-index: 10100;
  display: flex; align-items: center; justify-content: center;
}
.sq-level-editor.sq-hidden { display: none !important; }
.sq-level-editor__backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.55);
}
.sq-level-editor__box {
  position: relative; z-index: 1;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius, 6px); box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  padding: 28px 40px 24px; min-width: 180px; text-align: center;
}
.sq-level-editor__close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; font-size: 1.25rem; line-height: 1;
  color: var(--text-dim); cursor: pointer; padding: 0 4px;
}
.sq-level-editor__close:hover { color: var(--accent); }
.sq-level-editor__charname {
  font-size: 0.8125rem; font-weight: 600; color: var(--text-bright); margin-bottom: 18px;
}
.sq-level-editor__control {
  display: flex; align-items: center; justify-content: center; gap: 16px;
}
.sq-level-editor__step {
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-bright); font-size: 1.375rem; line-height: 1;
  width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.sq-level-editor__step:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.sq-level-editor__step:disabled { opacity: 0.3; cursor: default; }
.sq-level-editor__val {
  font-size: 2.5rem; font-weight: 700; color: var(--accent);
  min-width: 52px; display: inline-block; text-align: center; line-height: 1;
}
.sq-level-editor__label {
  font-size: 0.625rem; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px; margin-top: 10px;
}

/* ── Camp End Dialog ─────────────────────────────────────────────────────── */
.sq-camp-end-dialog {
  position: fixed; inset: 0; z-index: 10200;
  display: flex; align-items: center; justify-content: center;
}
.sq-camp-end-dialog.sq-hidden { display: none !important; }
.sq-camp-end-dialog__backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.45);
}
.sq-camp-end-dialog__box {
  position: relative; z-index: 1;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius, 6px); box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  padding: 20px 24px; min-width: 220px; text-align: center;
}
.sq-camp-end-dialog__title {
  font-size: 0.8125rem; font-weight: 700; color: var(--text-bright); margin-bottom: 6px;
}
.sq-camp-end-dialog__body {
  font-size: 0.6875rem; color: var(--text-dim); margin-bottom: 16px;
}
.sq-camp-end-dialog__rename {
  margin-bottom: 12px;
}
.sq-camp-end-dialog__rename input {
  width: 100%; box-sizing: border-box;
  background: var(--bg-input, var(--bg-hover)); border: 1px solid var(--border);
  border-radius: var(--radius, 4px); color: var(--text); font-size: 0.75rem;
  padding: 5px 8px; outline: none;
}
.sq-camp-end-dialog__rename input:focus {
  border-color: var(--accent, #7c5cbf);
}
.sq-camp-end-dialog__actions {
  display: flex; gap: 8px; justify-content: center;
}

.sq-flex-between { display: flex; justify-content: space-between; align-items: center; }
.sq-gap { gap: 12px; }

/* ── Input-action overlay (action palette narrative prompts) ─────────────── */

.sq-input-action-overlay {
  position: fixed; inset: 0; z-index: 9000;
}
.sq-input-action-overlay__backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.3);
}
.sq-input-action-overlay__card {
  position: fixed; z-index: 9001;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  width: min(300px, 44vw);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transform: scale(0.95); opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.sq-input-action-overlay__card.is-open { transform: scale(1); opacity: 1; }
.sq-input-action-overlay__title {
  font-size: 0.6875rem; color: var(--text-dim); margin-bottom: 8px;
}
.sq-input-action-overlay__field {
  width: 100%; padding: 6px 10px; margin-bottom: 10px;
  background: var(--bg-input, #2a2a3e);
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: 0.875rem;
  font-family: var(--font); box-sizing: border-box; outline: none;
}
.sq-input-action-overlay__field:focus {
  border-color: var(--accent, #7c5cbf);
}
.sq-input-action-overlay__actions {
  display: flex; justify-content: flex-end; gap: 6px;
}
