:root {
  --bg: #f7f5ef; --surface: #ffffff; --surface2: #efe9dc; --text: #1c2420;
  --muted: #6b7280; --border: #ddd6c4; --accent: #14532d; --accent2: #16a34a;
  --gold: #b8860b; --danger: #b91c1c; --fs: 16px;
  --shadow: 0 1px 3px rgba(20, 40, 25, .07), 0 4px 14px rgba(20, 40, 25, .05);
  --navy: #1b2a44; /* the logo artwork's own background, for seamless tiles */
}
/* Dark palette applies when the resolved theme is dark — the resolver in
   index.html/app.js follows the system by default and honors the profile's
   «ظاهر برنامه» choice (system / light / dark). */
:root[data-theme="dark"] {
  --bg: #101512; --surface: #1a201c; --surface2: #242b26; --text: #e8eae6;
  --muted: #9ca3af; --border: #37413a; --accent: #4ade80; --accent2: #22c55e; --gold: #d4a017;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html { font-size: var(--fs); }
body { margin: 0; font-family: Tahoma, 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent2); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent2) 22%, transparent); }
.hidden { display: none !important; }
.view { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .7rem; width: 100%; }
textarea { resize: vertical; }
.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface2); border-radius: 10px; padding: .65rem 1.1rem; cursor: pointer; text-align: center; text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); width: 100%; }
.btn.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn.small { padding: .4rem .8rem; width: auto; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: none; font-size: 1.25rem; cursor: pointer; padding: .4rem; }
.fld { display: block; margin: .7rem 0; }
.fld > span { display: block; margin-bottom: .35rem; color: var(--muted); font-size: .9rem; }
.notice { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: .7rem; margin: .7rem 0; }
.notice.warn { border-color: var(--gold); }
.notice.error { border-color: var(--danger); color: var(--danger); }
.muted { color: var(--muted); font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1rem; margin: .8rem 0; box-shadow: var(--shadow); }

/* entry */
.entry-wrap { max-width: 430px; margin: 0 auto; padding: 2rem 1.2rem 3rem; text-align: center; }
/* The full original logo artwork (emblem + its own calligraphy) as a
   rounded-square tile, always whole and uncropped: object-fit: contain on
   the artwork's own navy, never squeezed into a circle. */
.logo-box { width: 168px; height: 168px; margin: 0 auto 1rem; border-radius: 30px; background: var(--navy); box-shadow: 0 10px 28px rgba(10, 20, 40, .28); overflow: hidden; }
.logo-box img { width: 100%; height: 100%; object-fit: contain; display: block; }
.app-tag { color: var(--muted); margin: .2rem 0 1.2rem; font-size: 1.05rem; }
.entry-wrap .fld { text-align: start; }
.buy-box { margin-top: 2rem; border-top: 1px dashed var(--border); padding-top: 1rem; }
.buy-box .btn { width: 100%; }
#entry-lang { margin-top: 1rem; }

/* main shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem; background: var(--surface); border-bottom: 1px solid var(--border); padding: .5rem .8rem; box-shadow: 0 1px 8px rgba(0, 0, 0, .05); }
.logo-mini { width: 42px; height: 42px; border-radius: 11px; background: var(--navy); overflow: hidden; flex: none; }
.logo-mini img { width: 100%; height: 100%; object-fit: contain; display: block; }
.topbar-titles { flex: 1; min-width: 0; }
.topbar-name { font-weight: bold; }
.topbar-marja { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tab-pages { padding: .6rem .9rem 5.5rem; max-width: 860px; margin: 0 auto; }
.tabbar { position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: flex; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -1px 8px rgba(0, 0, 0, .05); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; background: none; border: none; padding: .45rem 0 .6rem; cursor: pointer; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: .1rem; font-size: .78rem; transition: color .15s ease; }
.tabbar button span { font-size: 1.2rem; }
.tabbar button.active { color: var(--accent); font-weight: bold; }

/* issues */
.search-row { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.search-row input { flex: 1; min-width: 180px; }
.chk { display: flex; gap: .35rem; align-items: center; font-size: .88rem; color: var(--muted); }
.chk input { width: auto; }
.chips { display: flex; gap: .45rem; overflow-x: auto; padding: .6rem 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: .35rem .8rem; cursor: pointer; font-size: .88rem; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.issue-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .9rem 1rem; margin: .6rem 0; box-shadow: var(--shadow); }
.issue-head { display: flex; gap: .5rem; align-items: center; margin-bottom: .45rem; flex-wrap: wrap; }
.issue-num { background: var(--accent); color: #fff; border-radius: 8px; padding: .1rem .55rem; font-weight: bold; font-size: .9rem; }
.issue-ch { color: var(--muted); font-size: .82rem; }
.issue-badge { border: 1px solid var(--gold); color: var(--gold); border-radius: 999px; padding: 0 .5rem; font-size: .75rem; }
.issue-text { line-height: 2; white-space: pre-wrap; word-break: break-word; }
.issue-text.clamped { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.issue-actions { display: flex; gap: .4rem; margin-top: .6rem; flex-wrap: wrap; }
.issue-actions button { border: 1px solid var(--border); background: var(--surface2); border-radius: 8px; padding: .3rem .6rem; cursor: pointer; font-size: .85rem; }
.issue-actions button.on { background: var(--gold); color: #fff; border-color: var(--gold); }
.daily { border-color: var(--gold); }
.daily h4 { margin: 0 0 .5rem; color: var(--gold); }

/* risala tab */
.collections-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.collection-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .8rem; cursor: pointer; }
.collection-card .ic { font-size: 1.6rem; }
.collection-card .ct { font-weight: bold; margin: .3rem 0; }
.collection-card .cc { color: var(--muted); font-size: .8rem; }
.chapter-row { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .7rem .9rem; margin: .4rem 0; cursor: pointer; width: 100%; text-align: start; }
.chapter-row .n { color: var(--muted); font-size: .85rem; }

/* marja photos */
.marja-photo { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); background: var(--surface2); flex: none; }
.marja-photo.sm { width: 30px; height: 30px; border-width: 1px; }
.marja-preview { display: flex; align-items: center; gap: .6rem; margin: -.2rem 0 .7rem; }
.profile-marja-row { display: flex; align-items: center; gap: .5rem; margin-top: .25rem; }
.group-title { display: flex; align-items: center; gap: .55rem; }

/* profile */
.profile-head { display: flex; gap: 1rem; align-items: center; }
.avatar-big { width: 74px; height: 74px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-size: 1.7rem; color: #fff; overflow: hidden; }
.avatar-big img { width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-weight: bold; font-size: 1.15rem; }
.avatar-grid { display: flex; gap: .5rem; flex-wrap: wrap; }
.avatar-opt { width: 52px; height: 52px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; color: #fff; overflow: hidden; padding: 0; }
.avatar-opt img { width: 100%; height: 100%; object-fit: cover; }
.avatar-opt.sel { border-color: var(--gold); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: .5rem; margin: .5rem 0; }
.stat-box { background: var(--surface2); border-radius: 10px; padding: .6rem; text-align: center; }
.stat-box b { display: block; font-size: 1.2rem; }
.bars { display: flex; gap: .3rem; align-items: flex-end; height: 54px; margin-top: .5rem; }
.bars .bar { flex: 1; background: var(--accent2); border-radius: 4px 4px 0 0; min-height: 3px; }
.file-btn { position: relative; overflow: hidden; }

/* overlay + admin */
#overlay-body, #admin-body { padding: .8rem .9rem 3rem; max-width: 860px; margin: 0 auto; }
.group-title { margin: 1.1rem 0 .3rem; font-weight: bold; color: var(--accent); }
table.codes { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.codes td, table.codes th { border-bottom: 1px solid var(--border); padding: .35rem; text-align: start; }
.toast { position: fixed; bottom: 5.2rem; inset-inline: 0; margin: 0 auto; width: fit-content; max-width: 90vw; background: var(--text); color: var(--bg); border-radius: 999px; padding: .55rem 1.1rem; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.note-edit { width: 100%; margin-top: .5rem; }
.hist-item { border-bottom: 1px solid var(--border); padding: .6rem 0; }
.hist-item .q { font-weight: bold; }
.rate-row { display: flex; gap: .5rem; margin-top: .6rem; }

@media (min-width: 900px) {
  /* Wide laptop layout: two-column issue/bookmark streams, roomier pages */
  #tab-pages { max-width: 1180px; padding-inline: 1.4rem; }
  #overlay-body, #admin-body { max-width: 1000px; }
  #issues-list, #bookmarks-list { display: grid; grid-template-columns: 1fr 1fr; gap: .1rem 1rem; align-items: start; }
  .collections-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
  .entry-wrap { max-width: 460px; }
  .logo-box { width: 184px; height: 184px; }
}
@media (min-width: 1400px) {
  #issues-list, #bookmarks-list { grid-template-columns: 1fr 1fr 1fr; }
}
