/* Deck Studio — the app's lapis and gold, for editing decks. */

:root {
  --lapis: #1C2B78;
  --lapis-deep: #131E5A;
  --lapis-night: #0D1545;
  --surface: #2A3B94;
  --raised: #34479F;
  --border: #4558B5;
  --gold: #FBD539;
  --gold-soft: #FFE680;
  --vermilion: #FF7A59;
  --green: #5FD39A;
  --text: #F4F1E8;
  --text-2: #C5CDF3;
  --text-3: #9FAAE6;
  --danger: #FF8A80;

  --display: "Irish Grover", "Marker Felt", fantasy;
  --body: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;

  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 20px;
  --shadow: 0 10px 28px rgba(8, 12, 40, 0.45);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--lapis);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.display {
  font-family: var(--display);
  font-weight: 400;
  color: var(--gold);
  letter-spacing: 0.01em;
}

h1, h2, p { margin: 0; }

a { color: var(--gold); }
a:hover { color: var(--gold-soft); }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--gold);
  color: var(--lapis-deep);
  padding: 8px 14px;
  border-radius: var(--radius-s);
  font-weight: 800;
  z-index: 10;
}
.skip-link:focus { left: 8px; }

/* Controls ------------------------------------------------------------------ */

label, legend {
  font-weight: 800;
  font-size: 14px;
  color: var(--text-2);
}

input[type="text"], input[type="email"], input[type="search"], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--lapis-deep);
  border: 2px solid var(--surface);
  border-radius: var(--radius-m);
  padding: 11px 14px;
  min-height: 46px;
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 0.8; }
input:focus, textarea:focus, select:focus { border-color: var(--gold); outline: none; }

.btn {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 999px;
  padding: 0 20px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-gold { background: var(--gold); color: var(--lapis-deep); }
.btn-gold:hover:not(:disabled) { background: var(--gold-soft); }
.btn-gold:disabled { background: var(--surface); color: var(--text-3); opacity: 1; }
.btn-outline { background: transparent; color: var(--text); box-shadow: inset 0 0 0 2px var(--border); }
.btn-outline:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--text-3); }
.btn-quiet { background: transparent; color: var(--text-2); padding: 0 12px; }
.btn-quiet:hover:not(:disabled) { color: var(--text); background: var(--lapis-deep); }
.btn-danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 2px rgba(255, 138, 128, 0.55); }
.btn-danger:hover:not(:disabled) { background: rgba(255, 138, 128, 0.12); }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 14px; }

.hint { font-size: 13px; color: var(--text-3); }
.status { min-height: 24px; color: var(--text-2); }
.status.is-error { color: var(--danger); }

.field { display: grid; gap: 8px; margin: 0; border: 0; padding: 0; }

.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); }

/* Full-screen states --------------------------------------------------------- */

.screen { min-height: 100vh; }
.screen-center { display: grid; place-items: center; padding: 24px; }

.signin {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  text-align: left;
}
.signin h1 { font-size: 44px; line-height: 1; }
.signin .lede { color: var(--text-2); }
.stack { display: grid; gap: 10px; }

.no-account { display: grid; gap: 12px; margin-top: 12px; padding: 22px; border-radius: 20px; background: var(--lapis-deep); border: 2px solid var(--surface); }
.no-account h2 { margin: 0; font-size: 18px; font-weight: 800; color: var(--text); }
.no-account p, .no-account li { color: var(--text-2); font-size: 15px; }
.no-account ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.no-account li::marker { color: var(--gold); font-weight: 800; }
.no-account .btn { justify-self: start; text-decoration: none; }
.signin a.btn { text-decoration: none; }

.cross {
  width: 56px;
  height: 56px;
  stroke: var(--gold);
  stroke-width: 4;
  stroke-linecap: round;
  fill: none;
}
.cross circle { fill: var(--gold); stroke: none; }

.loading { font-size: 32px; opacity: 0.6; }

/* Workspace ------------------------------------------------------------------ */

.workspace { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--lapis-deep);
  border-bottom: 2px solid var(--gold);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-name { font-size: 26px; }
.brand-sub { color: var(--text-3); font-weight: 700; font-size: 14px; }
.topnav { display: flex; gap: 4px; }
.tab {
  font: inherit;
  font-weight: 800;
  color: var(--text-2);
  background: transparent;
  border: 0;
  border-radius: var(--radius-s);
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--gold); }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.account-email { color: var(--text-3); font-size: 14px; font-weight: 700; }

main { flex: 1; display: flex; min-height: 0; }
main:focus { outline: none; }

/* Deck rail ------------------------------------------------------------------ */

.decks-layout { display: flex; flex: 1; min-width: 0; flex-wrap: wrap; }

.deck-rail {
  flex: 1 1 280px;
  max-width: 340px;
  background: var(--lapis-deep);
  border-right: 1px solid var(--surface);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 70px);
}
.rail-head { display: flex; gap: 8px; padding: 16px; position: sticky; top: 0; background: var(--lapis-deep); z-index: 1; }
.rail-head input { min-height: 40px; padding: 8px 12px; }

.deck-list { list-style: none; margin: 0; padding: 0 10px 16px; display: grid; gap: 4px; }
.deck-item {
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-m);
  background: transparent;
  cursor: pointer;
}
.deck-item:hover { background: var(--lapis-night); }
.deck-item.is-selected { background: var(--surface); }
.deck-thumb {
  width: 64px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  object-position: top;
  background: var(--raised);
  display: block;
}
.deck-item-title { font-family: var(--display); color: var(--gold); font-size: 17px; line-height: 1.15; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-item-meta { font-size: 13px; color: var(--text-3); font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge-hidden {
  font-size: 11px;
  font-weight: 800;
  color: var(--lapis-deep);
  background: var(--text-3);
  border-radius: 6px;
  padding: 1px 6px;
}
.rail-empty { padding: 16px; color: var(--text-3); }

/* Editor --------------------------------------------------------------------- */

.editor { flex: 999 1 560px; min-width: 0; padding: 0 28px 48px; }

.editor-empty {
  max-width: 420px;
  margin: 18vh auto 0;
  display: grid;
  gap: 8px;
  color: var(--text-2);
  text-align: center;
}
.editor-empty .display { font-size: 30px; }

.editor-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  background: var(--lapis);
  border-bottom: 1px solid var(--surface);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.save-state { color: var(--text-3); font-weight: 700; font-size: 14px; }
.save-state.is-dirty { color: var(--gold); }
.save-state.is-error { color: var(--danger); }
.editor-actions { display: flex; gap: 8px; }

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 36px;
  align-items: start;
}
.editor-main { display: grid; gap: 26px; min-width: 0; }

.title-input {
  font-family: var(--display) !important;
  font-size: 34px !important;
  color: var(--gold) !important;
  padding: 8px 14px !important;
}

/* Words */

.words { gap: 14px; }
.words legend { display: flex; align-items: center; gap: 10px; font-size: 20px; color: var(--text); margin-bottom: 4px; }
.count-pill {
  font-size: 13px;
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 2px 10px;
}

.add-words {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-l);
  background: var(--lapis-deep);
}
.add-words-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.word-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.word-tools input[type="search"] { flex: 1 1 200px; min-height: 40px; padding: 8px 12px; }

.word-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: var(--radius-l);
  background: var(--lapis-deep);
  counter-reset: word;
}
.word-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 40px;
  gap: 10px;
  align-items: start;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--surface);
}
.word-row:last-child { border-bottom: 0; }
.word-row::before {
  counter-increment: word;
  content: counter(word);
  color: var(--text-3);
  font-weight: 800;
  font-size: 13px;
  padding-top: 11px;
  text-align: right;
}
.word-fields { display: grid; gap: 6px; min-width: 0; }
.word-fields input {
  font-weight: 800;
  background: transparent;
  border-color: transparent;
  min-height: 40px;
  padding: 7px 10px;
}
.word-fields input:hover { border-color: var(--surface); }
.word-fields textarea {
  min-height: 0;
  font-size: 14px;
  color: var(--text-2);
  background: transparent;
  border-color: transparent;
  padding: 6px 10px;
  resize: none;
  overflow: hidden;
}
.word-fields textarea:hover { border-color: var(--surface); }
.word-fields input:focus, .word-fields textarea:focus { border-color: var(--gold); background: var(--lapis-night); }
.word-row.is-duplicate .word-fields input { border-color: var(--vermilion); }
.word-warning { font-size: 12px; color: var(--vermilion); font-weight: 700; padding-left: 10px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--surface); color: var(--danger); }
.icon-btn svg { width: 18px; height: 18px; }
.word-empty { color: var(--text-3); padding: 8px 2px; }

/* Danger */

.danger {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding-top: 22px;
  border-top: 1px solid var(--surface);
}
.danger h2 { font-size: 16px; color: var(--text); }
.danger p { color: var(--text-3); font-size: 14px; }

/* Side column */

.editor-side { display: grid; gap: 24px; position: sticky; top: 84px; }
.side-title { font-size: 14px; font-weight: 800; color: var(--text-2); margin-bottom: 8px; }

.publish {
  padding: 14px 16px;
  border-radius: var(--radius-l);
  background: var(--lapis-deep);
}
.switch { display: flex; gap: 14px; align-items: center; cursor: pointer; color: var(--text); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: var(--raised);
  position: relative;
  transition: background 0.15s;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--gold); outline-offset: 2px; }
.switch-label { display: grid; font-size: 14px; color: var(--text-3); font-weight: 600; }
.switch-label strong { color: var(--text); font-size: 15px; }

.drop-zone {
  position: relative;
  aspect-ratio: 360 / 250;
  border-radius: var(--radius-l);
  border: 2px dashed var(--border);
  background: var(--lapis-deep);
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.is-over { border-color: var(--gold); }
.drop-zone img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.drop-label {
  position: relative;
  z-index: 1;
  font-weight: 800;
  font-size: 14px;
  color: var(--text-2);
  padding: 8px 12px;
  border-radius: var(--radius-s);
  background: rgba(13, 21, 69, 0.75);
  text-align: center;
}
.drop-zone img:not([hidden]) + .drop-label { opacity: 0; transition: opacity 0.15s; }
.drop-zone:hover img:not([hidden]) + .drop-label,
.drop-zone:focus-visible img:not([hidden]) + .drop-label { opacity: 1; }
.cover .hint { margin-top: 8px; }

/* Phone preview: mirrors DeckCard in the app */

.phone {
  padding: 18px;
  border-radius: 34px;
  background: var(--lapis);
  box-shadow: inset 0 0 0 8px var(--lapis-night), var(--shadow);
  display: grid;
  place-items: center;
}
.phone-card {
  width: 172px;
  border-radius: 18px;
  overflow: hidden;
  background: var(--lapis-deep);
  box-shadow: 0 6px 16px rgba(8, 12, 40, 0.45);
}
.phone-art { position: relative; aspect-ratio: 360 / 250; background: var(--raised); }
.phone-art img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.preview-new {
  position: absolute;
  right: 8px;
  top: 8px;
  font-size: 10px;
  font-weight: 800;
  color: var(--lapis);
  background: var(--gold);
  border-radius: 6px;
  padding: 2px 6px;
}
.phone-rule { height: 2px; background: var(--gold); }
.phone-meta { padding: 9px 11px 11px; }
.preview-title { font-size: 17px; line-height: 1.05; overflow-wrap: anywhere; }
.preview-count { font-size: 11px; font-weight: 800; color: var(--text-2); margin-top: 3px; }
.preview .hint { margin-top: 10px; }

/* Editors panel -------------------------------------------------------------- */

.editors-panel { padding: 32px 28px 48px; width: min(760px, 100%); display: grid; gap: 18px; align-content: start; }
.editors-panel h1 { font-size: 38px; }
.editors-panel .lede { color: var(--text-2); }
.editor-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  border-radius: var(--radius-l);
  background: var(--lapis-deep);
}
.editor-list { list-style: none; margin: 0; padding: 0; border-radius: var(--radius-l); background: var(--lapis-deep); }
.editor-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface);
}
.editor-row:last-child { border-bottom: 0; }
.editor-row-email { flex: 1; font-weight: 800; overflow-wrap: anywhere; }
.role-badge { font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 6px; background: var(--surface); color: var(--text-2); }
.role-badge.is-owner { background: var(--gold); color: var(--lapis-deep); }

/* Dialog and toast ----------------------------------------------------------- */

dialog {
  border: 0;
  border-radius: var(--radius-l);
  background: var(--lapis-deep);
  color: var(--text);
  padding: 0;
  width: min(440px, calc(100% - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(13, 21, 69, 0.7); }
.dialog-body { display: grid; gap: 14px; padding: 24px; }
.dialog-body h2 { font-size: 20px; }
.dialog-body p { color: var(--text-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--lapis-deep);
  font-weight: 800;
  padding: 12px 18px;
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: calc(100% - 32px);
}
.toast.is-error { background: var(--danger); }

/* Small screens -------------------------------------------------------------- */

@media (max-width: 980px) {
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-side { position: static; order: -1; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; gap: 12px; }
  .account-email { display: none; }
  .deck-rail { max-width: none; min-height: 0; border-right: 0; border-bottom: 1px solid var(--surface); }
  .deck-list { max-height: 40vh; overflow-y: auto; }
  .editor { padding: 0 16px 40px; }
  .editors-panel { padding: 24px 16px 40px; }
  .editor-add { grid-template-columns: minmax(0, 1fr); }
  .title-input { font-size: 28px !important; }
}

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