/* ============================================================
   Fantasy Realms — App of Scoring
   Modern mobile-first UI
   ============================================================ */

:root {
  /* Suit fill colors (used behind white text in the hand) */
  --land-color: #3b1d13;
  --flood-color: #41437c;
  --weather-color: #6d7fb0;
  --flame-color: #b44347;
  --army-color: #312b2f;
  --wizard-color: #b83f83;
  --leader-color: #7b48a4;
  --beast-color: #4c8a49;
  --weapon-color: #6c6a6b;
  --artifact-color: #c1462f;
  --wild-color: #8a8687;
  --building-color: #463153;
  --outsider-color: #c9821f;
  --undead-color: #04635d;
  --cursed-item-color: #900c3f;

  /* Theme */
  --bg: #17110b;
  --bg-2: #1f170f;
  --surface: #241b12;
  --surface-2: #2c2117;
  --surface-3: #35281b;
  --line: #43331f;
  --line-soft: #3a2c1c;
  --text: #f2e8d5;
  --muted: #b1a288;
  --muted-2: #8a7d67;
  --gold: #e8bd68;
  --gold-soft: #caa24f;
  --green: #6cc267;
  --red: #e8776f;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);

  --header-h: 60px;
  --tabs-h: 52px;
  --radius: 14px;
  --radius-sm: 10px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

/* Per-suit accent (bright, for dark backgrounds) + fill token */
.land         { --suit:#c07a4c; --fill:var(--land-color); }
.flood        { --suit:#6d78e0; --fill:var(--flood-color); }
.weather      { --suit:#a6bced; --fill:var(--weather-color); }
.flame        { --suit:#e0625f; --fill:var(--flame-color); }
.army         { --suit:#9a8f9b; --fill:var(--army-color); }
.wizard       { --suit:#f06bb2; --fill:var(--wizard-color); }
.leader       { --suit:#a877dd; --fill:var(--leader-color); }
.beast        { --suit:#71c96c; --fill:var(--beast-color); }
.weapon       { --suit:#bdb9ba; --fill:var(--weapon-color); }
.artifact     { --suit:#ee7359; --fill:var(--artifact-color); }
.wild         { --suit:#dedadb; --fill:var(--wild-color); }
.building     { --suit:#a884cf; --fill:var(--building-color); }
.outsider     { --suit:#fbb43e; --fill:var(--outsider-color); }
.undead       { --suit:#2fb3a8; --fill:var(--undead-color); }
.cursed-item  { --suit:#e3477e; --fill:var(--cursed-item-color); }

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 50% -10%, rgba(232, 189, 104, .10), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
}

body.no-scroll { overflow: hidden; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

#app {
  max-width: 1040px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===================== Header ===================== */
.fr-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 14px;
  padding-right: 14px;
  background: linear-gradient(180deg, #2a1c11, #201509);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

.fr-brand { display: flex; align-items: center; flex: 0 0 auto; }
.fr-brand img {
  height: 34px;
  border-radius: 6px;
  display: block;
}

.fr-score {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 12px;
  line-height: 1;
}

.fr-score-cards {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .5px;
}
.fr-score-cards .sep { color: var(--muted-2); margin: 0 1px; }
#cardCount { color: var(--text); }

.fr-score-points {
  font-family: var(--font-display);
  font-size: 2.15rem;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .5), 0 0 18px rgba(232, 189, 104, .25);
  font-variant-numeric: tabular-nums;
  min-width: 3.1ch;
  text-align: right;
}

.fr-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.fr-icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--gold-soft);
  transition: background .15s, transform .1s, color .15s;
}
.fr-icon-btn:hover { background: var(--surface-3); color: var(--gold); }
.fr-icon-btn:active { transform: scale(.94); }
.fr-reset { color: var(--green); }
.fr-reset:hover { color: #8ad985; }

/* ===================== Mobile tabs ===================== */
.fr-tabs {
  position: sticky;
  top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  z-index: 25;
  height: var(--tabs-h);
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(23, 17, 11, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
}

.fr-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.fr-tab svg { opacity: .8; }
.fr-tab.is-active {
  background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
  color: var(--gold);
  border-color: var(--gold-soft);
  box-shadow: inset 0 0 0 1px rgba(232, 189, 104, .12);
}
.fr-tabbadge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-size: .78rem;
  font-weight: 800;
}
.fr-tab.is-active .fr-tabbadge { background: rgba(232, 189, 104, .18); color: var(--gold); }

/* ===================== Main / panels ===================== */
.fr-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.fr-panel { min-width: 0; }

/* ===================== Search ===================== */
.fr-search {
  position: sticky;
  top: calc(var(--header-h) + var(--tabs-h) + env(safe-area-inset-top, 0px) + 8px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 48px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.fr-search-icon { color: var(--muted-2); flex: 0 0 auto; }
#card-search {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  height: 100%;
}
#card-search::placeholder { color: var(--muted-2); }
#card-search::-webkit-search-cancel-button { display: none; }
.fr-search-clear {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
}
.fr-search-clear:hover { color: var(--text); }

.fr-no-results {
  text-align: center;
  color: var(--muted);
  padding: 30px 12px;
  font-style: italic;
}

/* ===================== Deck ===================== */
.fr-deck { display: flex; flex-direction: column; gap: 14px; }

.fr-suit-group {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.fr-suit-title {
  margin: 0;
  padding: 10px 14px;
  font-family: var(--font-display);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 9px;
}
.fr-suit-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--suit, var(--gold));
  box-shadow: 0 0 8px var(--suit, var(--gold));
  flex: 0 0 auto;
}

.fr-card-list { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 4px; }

.fr-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  border-left: 3px solid var(--suit);
  background: var(--surface-2);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
  user-select: none;
}
.fr-card:hover { background: var(--surface-3); border-color: var(--line); border-left-color: var(--suit); }
.fr-card:active { transform: scale(.985); }

.fr-str {
  flex: 0 0 auto;
  min-width: 30px;
  height: 26px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--suit);
  color: var(--suit);
  font-weight: 800;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.fr-card-name { flex: 1; font-size: .96rem; font-weight: 600; color: var(--text); }
.fr-add {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  color: var(--muted-2);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  transition: background .12s, color .12s;
}
.fr-card:hover .fr-add { background: var(--suit); color: #1a130d; }

/* Suit picker (Book of Changes) */
.fr-suit-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; padding: 6px; }
.fr-suit-choice {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  border-left: 3px solid var(--suit);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  text-align: left;
}
.fr-suit-choice:hover { background: var(--surface-3); }

/* ===================== Hand ===================== */
.fr-hand { display: flex; flex-direction: column; }

.fr-hand.is-empty::before {
  content: "Your hand is empty. Tap cards from the deck to build your hand and watch your score update live.";
  display: block;
  padding: 34px 22px;
  text-align: center;
  color: var(--muted);
  line-height: 1.6;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.fr-hand > .card { margin-bottom: 10px; }
.fr-discard > .card { margin-bottom: 10px; }
#discard-header { margin-bottom: 10px; }

.fr-hand .card, .fr-discard .card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  transition: transform .06s, border-color .12s;
}
.fr-hand .card:active { transform: scale(.99); }
.fr-hand .card:hover { border-color: var(--line); }

.list-group { list-style: none; margin: 0; padding: 0; }
.list-group-item { display: block; padding: 11px 14px; position: relative; font-size: .95rem; }

/* Main (suit-colored) row */
.fr-hand .list-group-item.land,   .fr-hand .list-group-item.flood,
.fr-hand .list-group-item.weather,.fr-hand .list-group-item.flame,
.fr-hand .list-group-item.army,   .fr-hand .list-group-item.wizard,
.fr-hand .list-group-item.leader, .fr-hand .list-group-item.beast,
.fr-hand .list-group-item.weapon, .fr-hand .list-group-item.artifact,
.fr-hand .list-group-item.wild,   .fr-hand .list-group-item.building,
.fr-hand .list-group-item.outsider,.fr-hand .list-group-item.undead,
.fr-hand .list-group-item.cursed-item,
.fr-discard .list-group-item.land,   .fr-discard .list-group-item.flood,
.fr-discard .list-group-item.weather,.fr-discard .list-group-item.flame,
.fr-discard .list-group-item.army,   .fr-discard .list-group-item.wizard,
.fr-discard .list-group-item.leader, .fr-discard .list-group-item.beast,
.fr-discard .list-group-item.weapon, .fr-discard .list-group-item.artifact,
.fr-discard .list-group-item.wild,   .fr-discard .list-group-item.building,
.fr-discard .list-group-item.outsider,.fr-discard .list-group-item.undead,
.fr-discard .list-group-item.cursed-item {
  background: var(--fill);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  border-left: 4px solid var(--suit);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

.fr-hand .badge, .fr-discard .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 7px;
  margin-right: 8px;
  border-radius: 7px;
  background: rgba(0, 0, 0, .38);
  color: #fff;
  font-size: .82rem;
  font-weight: 800;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

.points {
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* Sub rows: bonus / penalty / timing / action */
.fr-hand .list-group-item.bonus,
.fr-hand .list-group-item.penalty,
.fr-hand .list-group-item.timing,
.fr-hand .list-group-item.action-row {
  background: var(--surface);
  color: var(--muted);
  font-weight: 500;
  font-size: .82rem;
  border-top: 1px solid var(--line-soft);
  line-height: 1.4;
}
.fr-hand .list-group-item.timing { color: var(--gold-soft); border-top: 0; padding-bottom: 4px; }
.fr-hand .list-group-item.timing b { color: var(--gold-soft); }

span.bonus, .float-right.bonus { color: var(--green); font-weight: 800; }
span.penalty, .float-right.penalty { color: var(--red); font-weight: 800; }

.float-right { float: right; }
.cleared, .cleared:hover { text-decoration: line-through; opacity: .7; }

.blanked { opacity: .38; filter: grayscale(100%); }

/* ===================== Buttons in cards ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: .85rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
}
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-primary { background: linear-gradient(180deg, #b98a3e, #9a6f2c); border-color: #6f4f1e; color: #fff2d8; }
.btn-primary:hover { background: linear-gradient(180deg, #caa04f, #a97c31); }
.btn-secondary { background: var(--surface-3); border-color: var(--line); color: var(--text); }
.btn-secondary:hover { background: #40301f; }
.action-row .btn { margin-left: 6px; margin-bottom: 4px; }
.action-row #card-action-text-CH06, .action-row span { display: inline; }

/* ===================== Discard ===================== */
.fr-discard { display: none; flex-direction: column; }
#discard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold-soft);
}
.fr-discard .list-group-item { border-radius: 0; }
.fr-discard .card { cursor: pointer; }

/* ===================== Footer ===================== */
.fr-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted-2);
}
.fr-footer img { height: 26px; opacity: .8; filter: brightness(1.1); }
.fr-legal { font-size: .68rem; line-height: 1.4; }

/* ===================== Settings modal ===================== */
.fr-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(8, 5, 2, .66);
  backdrop-filter: blur(4px);
}
.fr-modal.is-open { display: flex; }

.fr-modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow: auto;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: fr-pop .18s ease-out;
}
@keyframes fr-pop { from { transform: translateY(14px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

.fr-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.fr-modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--gold);
}

#settings { padding: 18px; display: flex; flex-direction: column; gap: 18px; }
.fr-set-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.fr-set-block-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold-soft);
}
.fr-set-block-head img { height: 42px; border-radius: 8px; }

/* Switch */
.fr-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  color: var(--text);
  font-size: .95rem;
  user-select: none;
}
.fr-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.fr-slider {
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  position: relative;
  transition: background .16s;
}
.fr-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .16s, background .16s;
}
.fr-switch input:checked + .fr-slider { background: linear-gradient(180deg, #b98a3e, #9a6f2c); border-color: #6f4f1e; }
.fr-switch input:checked + .fr-slider::after { transform: translateX(20px); background: #fff2d8; }

/* Language dropdown */
.fr-dropdown { position: relative; }
.fr-dropbtn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
}
.fr-dropbtn img { height: 18px; }
.fr-dropbtn .caret { margin-left: auto; color: var(--muted); transition: transform .16s; }
.fr-dropdown.is-open .caret { transform: rotate(180deg); }
.fr-dropmenu {
  display: none;
  margin-top: 8px;
  padding: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  max-height: 260px;
  overflow: auto;
}
.fr-dropdown.is-open .fr-dropmenu { display: block; }
.dropdown-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: .95rem;
}
.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.active { background: rgba(232, 189, 104, .16); color: var(--gold); font-weight: 700; }

/* ===================== Responsive ===================== */
@media (min-width: 821px) {
  .fr-tabs { display: none; }
  .fr-panel--hand { position: sticky; top: calc(var(--header-h) + 16px); align-self: start; }
  .fr-search { top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 16px); }
}

@media (max-width: 820px) {
  .fr-main { grid-template-columns: 1fr; padding: 12px; }
  #app[data-tab="deck"] .fr-panel--hand { display: none; }
  #app[data-tab="hand"] .fr-panel--deck { display: none; }
  .fr-score-points { font-size: 1.9rem; }
  .fr-brand img { height: 30px; }
}

@media (max-width: 380px) {
  .fr-header { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .fr-icon-btn { width: 38px; height: 38px; }
  .fr-brand img { height: 26px; }
}
