:root {
  --paper: #fbf7ef;
  --ink: #101418;
  --muted: #6b6257;
  --rule: #ded5c6;
  --red: #9a2a2a;
  --accent: #1d3557;
  --radius: 3px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- masthead ---------- */

.masthead {
  border-bottom: 1px solid var(--rule);
  padding: 22px 24px 18px;
  text-align: center;
}

.wordmark {
  font-size: 30px;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.wordmark .pip { color: var(--red); margin-left: 5px; font-size: 0.8em; vertical-align: 2px; }
.tagline { margin: 4px 0 0; color: var(--muted); font-style: italic; font-size: 15px; }

/* ---------- sheet ---------- */

.sheet { max-width: 780px; margin: 0 auto; padding: 28px 24px 72px; }

.block {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fffdf8;
  padding: 20px 22px;
  margin-bottom: 18px;
}

.block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
  margin-bottom: 16px;
}

.block-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.block-actions { display: flex; align-items: center; gap: 12px; }

.price {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 2px 9px;
}

/* ---------- theme form ---------- */

.block--theme label { display: block; font-size: 15px; margin-bottom: 8px; color: var(--muted); }

#theme {
  width: 100%;
  font-family: var(--serif);
  font-size: 21px;
  padding: 11px 13px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

#theme:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font-family: var(--serif);
  font-size: 16px;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  margin-top: 12px;
}

button:hover:not(:disabled) { background: #000; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border-color: var(--rule);
  margin: 0;
  padding: 4px 12px;
  font-size: 14px;
}

.ghost-btn:hover:not(:disabled) { background: var(--paper); color: var(--ink); }
.primary { background: var(--red); border-color: var(--red); }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

/* ---------- hero ---------- */

.block--hero { display: flex; gap: 20px; align-items: center; }
.hero-text { flex: 1; min-width: 0; }
#deck-title { margin: 0; font-size: 34px; line-height: 1.15; letter-spacing: -0.01em; }
.theme-line { margin: 6px 0 0; color: var(--muted); font-style: italic; }
.meta { margin: 10px 0 0; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.hero-back {
  width: 76px; height: 106px; flex: none;
  border: 1px solid var(--rule); border-radius: 6px;
  background: repeating-linear-gradient(45deg, #f4ede0 0 6px, #fffdf8 6px 12px);
  display: grid; place-items: center;
  color: var(--red); font-size: 28px;
}

/* ---------- suits ---------- */

.suits { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.suit {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 13px 15px;
  background: var(--paper);
}

.suit-name { display: flex; align-items: baseline; gap: 8px; margin: 0 0 4px; font-size: 19px; }
.suit-sym { font-size: 20px; }
.suit-sym.red { color: var(--red); }
.suit-scope { margin: 0; font-size: 14px; color: var(--muted); }
.suit-why { margin: 8px 0 0; font-size: 14px; line-height: 1.45; }

/* ---------- court ---------- */

.court { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }

.court-card {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 10px 12px; background: var(--paper);
}

.court-rank {
  font-weight: 600; font-size: 15px; min-width: 30px;
  border-right: 1px solid var(--rule); padding-right: 8px;
}

.court-rank.red { color: var(--red); }
.court-name { font-size: 15px; }
.court-why { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- states ---------- */

.ghost {
  color: transparent;
  background: linear-gradient(90deg, #efe8db 25%, #f7f1e6 50%, #efe8db 75%);
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.status { text-align: center; color: var(--muted); font-style: italic; min-height: 22px; }
.status.err { color: var(--red); font-style: normal; }

.foot {
  border-top: 1px solid var(--rule);
  padding: 18px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

@media (max-width: 620px) {
  .suits { grid-template-columns: 1fr; }
  .block--hero { flex-direction: column-reverse; align-items: flex-start; }
  #deck-title { font-size: 27px; }
}

/* ---------- inline editing ---------- */

/*
 * Edit affordance must be visible without being noisy: a dotted underline on
 * hover plus a pencil. The previous build claimed things were editable and
 * offered no affordance at all.
 */
.edit { cursor: text; border-radius: 2px; transition: background 0.12s, box-shadow 0.12s; }

body:not(.is-guest) .edit:hover {
  background: #fdf6e6;
  box-shadow: 0 0 0 4px #fdf6e6;
}

body:not(.is-guest) .edit:hover::after {
  content: "✎";
  font-size: 0.72em;
  color: var(--muted);
  margin-left: 6px;
  vertical-align: 1px;
}

body:not(.is-guest) .edit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.edit.is-editing, .edit.is-editing:hover { background: none; box-shadow: none; }
.edit.is-editing::after { content: none; }

.edit-input {
  font: inherit;
  color: inherit;
  width: 100%;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: #fff;
  resize: vertical;
}

.edit-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(29, 53, 87, 0.14); }

/* Guests see a read-only document and a fork button, never edit affordances. */
body.is-guest .edit { cursor: default; }
body.is-guest .block-actions button { display: none; }

/* ---------- suit confirmation ---------- */

.confirm-row {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  text-align: center;
}

.confirm-row .primary { margin-top: 0; }

.suit.is-confirmed {
  border-color: #cfc4ad;
  background: #fdfaf3;
}

.suit.is-confirmed .suit-name::after {
  content: "✓";
  color: #4a7c59;
  font-size: 0.78em;
  margin-left: auto;
  padding-left: 8px;
}

.suit-name { justify-content: flex-start; }

.court-body { min-width: 0; flex: 1; }

/* ---------- court, grouped by suit ---------- */

.court { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.court-group { display: flex; flex-direction: column; gap: 8px; }

.court-suit {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--rule);
}

.court-suit .suit-sym { font-size: 15px; }

@media (max-width: 620px) { .court { grid-template-columns: 1fr; } }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- next: the fork ---------- */

.paths { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 4px; }

.path {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

.path--primary { border-color: #c9a227; background: #fffdf4; }
.path h3 { margin: 0 0 8px; font-size: 19px; }
.path-body { margin: 0 0 12px; font-size: 15px; color: var(--muted); flex: 1; }
.path-price { margin: 0 0 12px; font-size: 14px; }
.path .primary, .path .wide { margin: 0; width: 100%; }
.wide { padding: 10px 18px; }

.card-picker { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); }
.picker-head { margin: 0 0 10px; font-size: 15px; }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }

.pick {
  text-align: left;
  font: inherit;
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 9px 12px;
  margin: 0;
  cursor: pointer;
}

.pick:hover:not(:disabled) { border-color: var(--accent); background: #fff; }
.pick .pick-rank { font-weight: 600; margin-right: 7px; }
.pick .pick-rank.red { color: var(--red); }
.pick .pick-suit { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

.build-result { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); }
.build-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }

.plate {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #efe8db;
  aspect-ratio: 11 / 15;
  object-fit: cover;
}

.credits { font-size: 13px; color: var(--muted); line-height: 1.5; }
.credits strong { color: var(--ink); }
.credits a { color: var(--accent); }
.warn { color: #8a5a00; background: #fdf6e3; border: 1px solid #e8d9a8;
        border-radius: 3px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }

@media (max-width: 620px) {
  .paths { grid-template-columns: 1fr; }
  .build-grid { grid-template-columns: 1fr; }
}

/* Operator badge, so it is obvious when caps are being bypassed. */
body.is-admin .masthead::after {
  content: "unlimited";
  display: inline-block;
  margin-left: 10px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #4a7c59;
  border: 1px solid #4a7c59;
  border-radius: 999px;
  padding: 1px 8px;
  vertical-align: 3px;
}

/* ---------- demo allowance ---------- */

.grant-banner {
  border: 1px solid #c9a227;
  background: #fffdf4;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 18px;
  font-size: 14px;
}

.grant-banner .g-num { font-weight: 600; }
.grant-banner.spent { border-color: var(--rule); background: var(--paper); color: var(--muted); }

/* ---------- operator panel ---------- */

.block--admin { border-color: #4a7c59; background: #fbfdfb; }
.mint-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.mint-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.mint-form input {
  font: inherit; font-size: 14px; padding: 5px 7px;
  border: 1px solid var(--rule); border-radius: var(--radius); background: #fff;
}
.invite-list { margin-top: 14px; display: flex; flex-direction: column; gap: 7px; }
.invite {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 8px 11px; background: #fff; font-size: 13px;
}
.invite code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; background: var(--paper); padding: 2px 6px; border-radius: 2px;
  cursor: pointer; border: 1px solid var(--rule);
}
.invite .inv-label { font-weight: 600; }
.invite .inv-meta { color: var(--muted); margin-left: auto; }
.invite.is-dead { opacity: 0.5; }

/* ---------- change-it advice ---------- */

.advice { display: flex; gap: 8px; margin-top: 14px; }
.advice input {
  flex: 1; font: inherit; font-size: 15px; padding: 8px 11px;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper);
}
.advice input:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: #fff; }
.advice button { margin: 0; }
body.is-guest .advice { display: none; }

/* ---------- the court frame ---------- */

.court-frame { display: flex; flex-direction: column; gap: 6px; }

.court-row { display: grid; grid-template-columns: 116px repeat(5, 1fr); gap: 6px; align-items: stretch; }
.court-head { display: grid; grid-template-columns: 116px repeat(5, 1fr); gap: 6px; }

.court-head span {
  text-align: center; font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted); padding-bottom: 2px;
}
.court-head span:first-child { text-align: left; }

.court-suit-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 600; padding: 6px 2px; min-width: 0;
}
.court-suit-label .nm {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.slot {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  min-height: 74px;
  padding: 7px 8px;
  display: flex; flex-direction: column; gap: 2px;
}

.slot.is-empty { border-style: dashed; background: transparent; }
.slot.drop-target { border-color: var(--accent); background: #eef2f7; }
.slot.dragging { opacity: 0.4; }

.slot-name {
  font-size: 13.5px; line-height: 1.25; cursor: grab; word-break: break-word;
}
.slot-name:active { cursor: grabbing; }
.slot-why { font-size: 11px; color: var(--muted); line-height: 1.3; }

.slot-actions {
  position: absolute; top: 3px; right: 3px; display: none; gap: 2px;
}
.slot:hover .slot-actions { display: flex; }
body.is-guest .slot-actions { display: none !important; }

.slot-actions button {
  margin: 0; padding: 0; width: 18px; height: 18px; line-height: 1;
  font-size: 12px; border-radius: 2px;
  background: #fff; color: var(--muted); border: 1px solid var(--rule);
}
.slot-actions button:hover { color: var(--ink); border-color: var(--accent); }

.slot-empty-actions {
  display: flex; gap: 4px; align-items: center; justify-content: center;
  height: 100%; opacity: 0; transition: opacity 0.12s;
}
.slot:hover .slot-empty-actions { opacity: 1; }
body.is-guest .slot-empty-actions { display: none; }

.slot-empty-actions button {
  margin: 0; padding: 3px 7px; font-size: 11px;
  background: #fff; color: var(--muted); border: 1px solid var(--rule);
}
.slot-empty-actions button:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }

.slot-input {
  font: inherit; font-size: 13px; width: 100%;
  border: 1px solid var(--accent); border-radius: 2px; padding: 3px 5px;
}

@media (max-width: 720px) {
  .court-row, .court-head { grid-template-columns: 84px repeat(5, 1fr); }
  .slot { min-height: 64px; padding: 5px 6px; }
  .slot-why { display: none; }
}

/* ---------- the court frame: ranks down, suits across ---------- */

.court-frame { display: flex; flex-direction: column; gap: 6px; }

.court-head,
.court-row {
  display: grid;
  grid-template-columns: 34px repeat(4, 1fr);
  gap: 6px;
}

.court-head .ch {
  display: flex; align-items: baseline; gap: 5px; justify-content: center;
  padding-bottom: 4px; border-bottom: 1px solid var(--rule);
  font-size: 13px; min-width: 0;
}
.court-head .ch b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.court-head .ch i { font-style: normal; }

.court-rank-label {
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--muted);
}

.slot {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  min-height: 76px;
  padding: 7px 8px;
  display: flex; flex-direction: column; gap: 2px;
}

.slot.is-empty { border-style: dashed; background: transparent; }
.slot.drop-target { border-color: var(--accent); background: #eef2f7; }
.slot.dragging { opacity: 0.4; }

.slot-name { font-size: 13.5px; line-height: 1.25; cursor: grab; word-break: break-word; }
.slot-name:active { cursor: grabbing; }
.slot-why { font-size: 11px; color: var(--muted); line-height: 1.3; }

.slot-actions { position: absolute; top: 3px; right: 3px; display: none; gap: 2px; }
.slot:hover .slot-actions { display: flex; }
body.is-guest .slot-actions { display: none !important; }

.slot-actions button {
  margin: 0; padding: 0; width: 18px; height: 18px; line-height: 1;
  font-size: 12px; border-radius: 2px;
  background: #fff; color: var(--muted); border: 1px solid var(--rule);
}
.slot-actions button:hover { color: var(--ink); border-color: var(--accent); }

.slot-empty-actions {
  display: flex; gap: 4px; align-items: center; justify-content: center;
  flex-wrap: wrap; height: 100%; opacity: 0; transition: opacity 0.12s;
}
.slot:hover .slot-empty-actions { opacity: 1; }
body.is-guest .slot-empty-actions { display: none; }

.slot-empty-actions button {
  margin: 0; padding: 3px 7px; font-size: 11px;
  background: #fff; color: var(--muted); border: 1px solid var(--rule);
}
.slot-empty-actions button:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }

.slot-input { font: inherit; font-size: 13px; width: 100%;
  border: 1px solid var(--accent); border-radius: 2px; padding: 3px 5px; }

/* ---------- skeletons ---------- */

.sk-bar {
  display: block;
  height: 0.72em;
  margin: 5px 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #ece5d8 25%, #f6f0e5 50%, #ece5d8 75%);
  background-size: 200% 100%;
  animation: sweep 1.25s ease-in-out infinite;
}

.sk-bar.sk-gap { margin-top: 12px; }
.suit.sk, .slot.sk { border-style: solid; }
.slot.sk { justify-content: center; align-items: center; }
.slot.sk .sk-bar { margin: 0; }

/* Stagger so the row reads as a wave rather than a strobe. */
.court-row:nth-child(2) .sk-bar { animation-delay: 0.06s; }
.court-row:nth-child(3) .sk-bar { animation-delay: 0.12s; }
.court-row:nth-child(4) .sk-bar { animation-delay: 0.18s; }
.court-row:nth-child(5) .sk-bar { animation-delay: 0.24s; }
.court-row:nth-child(6) .sk-bar { animation-delay: 0.3s; }
.suit.sk:nth-child(2) .sk-bar { animation-delay: 0.08s; }
.suit.sk:nth-child(3) .sk-bar { animation-delay: 0.16s; }
.suit.sk:nth-child(4) .sk-bar { animation-delay: 0.24s; }

@keyframes sweep {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ---------- the typing throbber ---------- */

.status { min-height: 26px; }

.status.typing::after {
  content: "";
  display: inline-block;
  width: 0.55em; height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.16em;
  background: var(--muted);
  animation: caret 1s steps(1) infinite;
}

@keyframes caret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .sk-bar { animation: none; }
  .status.typing::after { animation: none; }
}

@media (max-width: 720px) {
  .court-head, .court-row { grid-template-columns: 26px repeat(4, 1fr); gap: 4px; }
  .court-head .ch b { display: none; }
  .slot { min-height: 62px; padding: 5px; }
  .slot-why { display: none; }
}
