/* The game's palette (city-profiles/riyadh.yaml game.theme). 8 px corners, never pills. */
:root {
  --panel: #F6F3EC;
  --panel2: #ECE9E2;
  --line: #DDD9D0;
  --text: #353A3A;
  --muted: #747975;
  --accent: #00A86B;
  --accent-dark: #008052;
  --accent-text: #00895A;
  --on-accent: #FFFFFF;
  --good: #00A86B;
  --warn: #C27A1F;
  --bad: #B8432E;
  --bg: #E4E1D9;
  --r: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Alexandria", "Segoe UI", Tahoma, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
button, input, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 28px; height: 28px; border-radius: 6px; background: var(--accent); flex: none;
  box-shadow: inset 0 -8px 0 var(--accent-dark); }
.title { font-weight: 700; font-size: 15px; }
.sub { color: var(--muted); font-size: 12px; }
.clock { text-align: center; }
.year { font-weight: 700; font-size: 20px; }
.date { color: var(--muted); font-size: 12px; }
.controls { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.speeds { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel2); }
.speeds button { border: 0; background: transparent; padding: 6px 10px; cursor: pointer; min-width: 44px; min-height: 34px; }
.speeds button + button { border-inline-start: 1px solid var(--line); }
.speeds button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.live { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--good); }
.live.off .dot { background: var(--bad); }
.live.paused .dot { background: var(--warn); }

.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); border-radius: var(--r);
  padding: 6px 14px; min-height: 34px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--panel2); }

.keybar { display: flex; gap: 8px; align-items: center; padding: 8px 16px; background: var(--panel2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.keybar input { border: 1px solid var(--line); border-radius: var(--r); padding: 6px 10px; background: var(--panel); min-width: 0; flex: 1 1 180px; max-width: 280px; }
.keybar .msg { color: var(--muted); font-size: 12px; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; min-width: 0; }
.tile .k { color: var(--muted); font-size: 12px; }
.tile .v { font-size: 26px; font-weight: 700; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.tile .d { font-size: 12px; min-height: 18px; }
.up { color: var(--good); }
.down { color: var(--bad); }
.flatc { color: var(--muted); }

/* ---------- alerts ---------- */
.alerts { display: flex; gap: 8px; flex-wrap: wrap; }
.alerts:empty { display: none; }
.alert { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-inline-start: 4px solid var(--warn); border-radius: var(--r); padding: 6px 10px; font-size: 12px; cursor: pointer; max-width: 100%; }
.alert.bad { border-inline-start-color: var(--bad); }
.alert b { font-weight: 600; }
.alert .names { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- card + table ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.cardhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
h2 { margin: 0; font-size: 15px; font-weight: 600; }
.tools { display: flex; align-items: center; gap: 10px; }
.tools input { border: 1px solid var(--line); border-radius: var(--r); padding: 6px 10px; background: var(--panel2); width: 200px; max-width: 50vw; }
.count { color: var(--muted); font-size: 12px; }

.tablewrap { max-height: 62vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--panel2); color: var(--muted); font-weight: 500; font-size: 12px; cursor: pointer; user-select: none; z-index: 1; }
th.n, td.n { text-align: left; }
th.sorted::after { content: " ▾"; color: var(--accent); }
th.sorted.asc::after { content: " ▴"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel2); }
tbody tr.sel { box-shadow: inset -3px 0 0 var(--accent); background: var(--panel2); }
tr.bankrupt td { color: var(--bad); background: rgba(184, 67, 46, .07); }
tr.flat td { background: rgba(194, 122, 31, .09); }
tr.flat td.name::after { content: "ثابت ٣ سنوات"; margin-inline-start: 8px; font-size: 11px; color: var(--warn); border: 1px solid var(--warn); border-radius: 4px; padding: 0 4px; }
tr.bankrupt td.name::after { content: "مفلس"; margin-inline-start: 8px; font-size: 11px; color: var(--bad); border: 1px solid var(--bad); border-radius: 4px; padding: 0 4px; }
tr.you td.name { font-weight: 700; }
td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
td.rank { color: var(--muted); }
.style { font-size: 12px; color: var(--muted); }
.money { font-weight: 600; }

/* ---------- notes ---------- */
.noteform { display: grid; grid-template-columns: 160px 1fr auto; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.noteform input, .noteform textarea { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; background: var(--panel2); resize: vertical; min-width: 0; }
.notes { padding: 4px 14px 10px; }
.note { padding: 10px 0; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .meta { display: flex; gap: 10px; color: var(--muted); font-size: 12px; }
.note .meta b { color: var(--text); font-weight: 600; }
.note .t { white-space: pre-wrap; margin-top: 2px; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 12px 0; font-size: 13px; }
.foot { color: var(--muted); font-size: 11px; text-align: center; }

/* ---------- side panel (left edge in a right-to-left page) ---------- */
.panel { position: fixed; top: 0; bottom: 0; left: 0; width: min(480px, 100vw); z-index: 20;
  background: var(--panel); border-inline-start: 1px solid var(--line); box-shadow: 8px 0 24px rgba(53, 58, 58, .12);
  transform: translateX(-102%); transition: transform .22s ease; display: flex; flex-direction: column; }
.panel.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(53, 58, 58, .25); z-index: 15; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.pname { font-size: 18px; font-weight: 700; }
.pmeta { color: var(--muted); font-size: 12px; }
.close { min-width: 40px; }
.pbody { overflow-y: auto; padding: 0 16px 24px; }
h3 { font-size: 13px; font-weight: 600; margin: 18px 0 8px; display: flex; gap: 8px; align-items: baseline; }
.hint { color: var(--muted); font-weight: 400; font-size: 11px; }
.ptiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.ptile { background: var(--panel2); border-radius: var(--r); padding: 8px 10px; min-width: 0; }
.ptile .k { color: var(--muted); font-size: 11px; }
.ptile .v { font-size: 17px; font-weight: 700; text-align: right; }

.chart { position: relative; background: var(--panel2); border-radius: var(--r); padding: 6px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .tip { position: absolute; pointer-events: none; background: var(--text); color: var(--panel); border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); }
.chart .none { color: var(--muted); padding: 30px 0; text-align: center; font-size: 12px; }

.ledger { width: 100%; }
.ledger td { padding: 6px 4px; font-size: 13px; }
.ledger td.n { font-weight: 600; }
.ledger tr.total td { border-bottom: 0; font-weight: 700; }
.ledger .bar { height: 6px; border-radius: 2px; background: var(--good); min-width: 2px; }
.ledger .bar.out { background: var(--bad); }
.ledger td.barc { width: 30%; }

.list .it { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list .it:last-child { border-bottom: 0; }
.list .it .l { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .it .r { white-space: nowrap; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-inline-start: 6px; }
.tag.g { color: var(--accent-text); border-color: var(--accent); }
.tag.w { color: var(--warn); border-color: var(--warn); }

/* ---------- iPad and phone ---------- */
@media (max-width: 900px) {
  .c-props, .c-rent { display: none; }
}
@media (max-width: 700px) {
  .top { grid-template-columns: 1fr auto; }
  .brand .sub { display: none; }
  .clock { text-align: left; }
  .controls { grid-column: 1 / -1; justify-content: space-between; }
  .speeds { flex: 1 1 100%; order: 3; }
  .speeds button { flex: 1; min-width: 0; padding: 6px 4px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .v { font-size: 21px; }
  .c-style, .c-cash, .c-debt { display: none; }
  th, td { padding: 8px 6px; }
  td.name { max-width: 150px; }
  tr.flat td.name::after, tr.bankrupt td.name::after { display: none; }
  .tools input { width: 150px; }
  .noteform { grid-template-columns: 1fr; }
  main { padding: 12px 16px; gap: 12px; }
}
.ledger .bar.zero { background: var(--line); }
