:root {
  color-scheme: light;
  --ink: #20342d;
  --muted: #64756b;
  --felt: #164f3f;
  --line: #dee6df;
  --paper: #f5f7f4;
  --red: #b24d48;
  font-family: Tahoma, "Vazirmatn", Arial, sans-serif;
  font-size: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); line-height: 1.65; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; opacity: .6; }
button:focus-visible, input:focus-visible, summary:focus-visible,
.segmented input:focus-visible + span { outline: 3px solid #d5a850; outline-offset: 2px; }
h1, h2, p { margin-top: 0; }
.shell { min-height: 100vh; }
.topbar, main { width: min(100%, 1080px); margin-inline: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 22px 14px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 12px; background: var(--felt); color: white; font-size: 24px; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: .78rem; font-weight: 600; }
h1 { margin: 0; font-size: 1.32rem; line-height: 1.35; }
h2 { margin: 0; font-size: 1.14rem; line-height: 1.4; }
.ghost { min-height: 43px; padding: 8px 14px; border: 1px solid #c9d8cb; border-radius: 10px; background: white; color: var(--felt); font-weight: 700; }
.ghost:hover, .icon-button:hover { background: #edf5ee; }
.reset-button { white-space: nowrap; }
main { padding: 0 22px 30px; }

.scoreboard { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 19px; background: white; box-shadow: 0 5px 20px #20342d0a; }
.team-card { min-width: 0; padding: 14px 19px 13px; border-radius: 13px; background: #eff7f0; }
.team-b { background: #fff6ed; }
.team-label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.edit-hint { font-size: .85rem; }
.team-name { display: block; width: 100%; max-width: 290px; margin: 2px 0 0; padding: 1px 0; border: 0; border-bottom: 1px dashed #adbdb1; border-radius: 0; outline-offset: 2px; background: transparent; color: var(--ink); font-size: 1.03rem; font-weight: 700; text-overflow: ellipsis; }
.team-name:focus { border-bottom-color: var(--felt); }
.team-score { margin-top: 4px; color: #165d41; font-size: clamp(2.5rem, 5vw, 3.45rem); line-height: 1.14; font-weight: 800; font-variant-numeric: tabular-nums; }
.team-b .team-score { color: #9e591f; }
.score-foot { min-height: 1.5em; margin-top: 3px; color: #526b5a; font-size: .76rem; font-weight: 600; }
.team-b .score-foot { color: #876648; }
.score-divider { display: grid; place-items: center; color: var(--muted); font-size: .73rem; white-space: nowrap; }

.work-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 14px; margin-top: 14px; }
.panel { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 17px; background: white; box-shadow: 0 4px 16px #20342d08; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.panel-heading .eyebrow { color: #477866; }
.hand-counter { flex: none; padding: 4px 10px; border-radius: 99px; background: #edf4ee; color: #315e4c; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.field-group { min-width: 0; margin: 0 0 16px; padding: 0; border: 0; }
.field-group legend { margin-bottom: 8px; font-size: .88rem; font-weight: 700; }
.segmented { display: flex; gap: 5px; padding: 4px; border: 1px solid #e2e9e2; border-radius: 11px; background: #f4f6f3; }
.segmented label { position: relative; flex: 1; min-width: 0; text-align: center; cursor: pointer; }
.segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.segmented span { display: grid; min-height: 41px; place-items: center; padding: 7px 4px; border: 1px solid transparent; border-radius: 8px; color: #53675b; font-size: .86rem; font-weight: 700; line-height: 1.35; }
.segmented input:checked + span { border-color: #a7c4af; background: white; color: #14543b; box-shadow: 0 2px 6px #20342d0e; }
.contract-note { display: block; margin-top: 7px; color: var(--muted); font-size: .79rem; line-height: 1.6; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.field-row.single { grid-template-columns: 1fr; }
.field { min-width: 0; }
.field span { display: block; margin-bottom: 6px; font-size: .87rem; font-weight: 700; }
.field input, .rules-controls input { width: 100%; height: 48px; padding: 7px 12px; border: 1px solid #cbd9cd; border-radius: 10px; background: white; color: var(--ink); direction: ltr; text-align: right; font-size: 1.05rem; }
.field input::placeholder { color: #98a79d; }
.field small { display: block; min-height: 1.7em; margin-top: 4px; color: var(--muted); font-size: .75rem; }
.estimate { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin: 11px 0 13px; padding: 11px 13px; border: 1px solid #d7e9db; border-radius: 10px; background: #f0f8f1; }
.estimate span { color: #4d715c; font-size: .78rem; }
.estimate strong { font-size: .84rem; line-height: 1.6; }
.form-error { margin: 0 0 10px; color: var(--red); font-size: .83rem; }
.form-actions { display: flex; gap: 9px; }
.primary { flex: 1; min-height: 48px; padding: 9px 18px; border: 1px solid var(--felt); border-radius: 10px; background: var(--felt); color: white; font-weight: 700; }
.primary:hover { background: #22654f; }
.end-notice { margin: 0; padding: 16px; border: 1px solid #d7e9db; border-radius: 11px; background: #f0f8f1; color: #204e37; font-size: .92rem; line-height: 1.9; }

.empty-state { display: flex; min-height: 150px; align-items: center; justify-content: center; flex-direction: column; padding: 14px; border: 1px dashed #d4dfd6; border-radius: 11px; background: #fafcf9; text-align: center; }
.empty-symbol { color: #92ac98; font-size: 2rem; line-height: 1.1; }
.empty-state strong { margin-top: 5px; font-size: .91rem; }
.empty-state p { max-width: 270px; margin: 3px 0 0; color: var(--muted); font-size: .79rem; }
.history-list { max-height: 545px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.history-list li { display: grid; grid-template-columns: 29px minmax(0, 1fr) auto; align-items: start; gap: 8px; padding: 11px 0; border-top: 1px solid #e9eee9; }
.history-list li:first-child { padding-top: 0; border-top: 0; }
.hand-number { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 7px; background: #edf4ee; color: #35614b; font-size: .76rem; font-weight: 700; }
.history-details { min-width: 0; }
.history-details strong { font-size: .87rem; }
.history-details small { display: block; margin-top: 2px; color: var(--muted); font-size: .74rem; }
.history-numbers { display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 3px; font-size: .82rem; }
.history-actions { display: flex; gap: 2px; }
.icon-button { min-height: 32px; padding: 4px 5px; border: 0; border-radius: 6px; background: transparent; color: #486957; font-size: .78rem; white-space: nowrap; }
.history-actions .remove { color: #a4554e; }
.history-actions .remove:hover { background: #fff0ee; }
.positive { color: #176744; }
.negative { color: #ab4541; }

.archive-panel { margin-top: 14px; padding: 14px 19px; }
.archive-panel summary { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .97rem; font-weight: 700; list-style: none; }
.archive-panel summary::-webkit-details-marker { display: none; }
.archive-panel summary::before { content: '◂'; color: var(--felt); font-size: 1.15rem; }
.archive-panel[open] summary::before { transform: rotate(-90deg); }
.archive-help { margin: 12px 0; color: var(--muted); font-size: .8rem; }
.archive-empty { margin: 8px 0 2px; color: var(--muted); font-size: .84rem; }
.archive-list { max-height: 390px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.archive-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-top: 1px solid #e9eee9; }
.archive-list li > div { min-width: 0; }
.archive-list strong { display: block; font-size: .87rem; overflow-wrap: anywhere; }
.archive-list small { display: block; margin-top: 2px; color: var(--muted); font-size: .75rem; }
.archive-list .ghost { min-height: 38px; padding: 6px 12px; font-size: .8rem; }

.rules { display: grid; grid-template-columns: minmax(0, 1fr) minmax(210px, 260px); align-items: start; gap: 14px; margin-top: 14px; padding: 16px 19px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.rules-details { min-width: 0; }
.rules-details summary { width: fit-content; padding: 6px 0; color: var(--felt); font-size: .9rem; font-weight: 700; cursor: pointer; }
.rules-details summary::marker { color: var(--felt); }
.rules-body { padding: 7px 0 0; }
.rules-body p { margin: 0 0 8px; color: var(--muted); font-size: .82rem; line-height: 1.85; }
.rules-controls label { display: block; margin-bottom: 6px; font-size: .78rem; font-weight: 700; }
.rules-controls input { height: 42px; }
.rules-controls small { display: block; margin-top: 4px; color: var(--muted); font-size: .72rem; }
footer { padding: 14px 18px 22px; color: #829087; font-size: .73rem; text-align: center; }

@media (max-width: 760px) {
  .work-grid { grid-template-columns: 1fr; }
  .rules { grid-template-columns: 1fr; }
  .rules-controls { max-width: 360px; }
}
@media (max-width: 520px) {
  .topbar { padding: 13px 13px 11px; }
  .brand-mark { width: 37px; height: 37px; font-size: 21px; }
  h1 { font-size: 1.13rem; }
  .topbar .eyebrow { font-size: .69rem; }
  .reset-button { min-height: 40px; padding: 7px 9px; font-size: .79rem; }
  main { padding: 0 10px 24px; }
  .scoreboard { gap: 4px; padding: 6px; border-radius: 15px; }
  .team-card { padding: 12px 9px; border-radius: 10px; }
  .team-label { font-size: .7rem; }
  .team-name { font-size: .88rem; }
  .team-score { margin-top: 6px; font-size: clamp(1.9rem, 8vw, 2.5rem); }
  .score-foot { font-size: .7rem; line-height: 1.5; }
  .score-divider { font-size: .65rem; }
  .work-grid { gap: 10px; margin-top: 10px; }
  .panel { padding: 16px; border-radius: 14px; }
  .panel-heading { margin-bottom: 14px; }
  .field-row { gap: 8px; }
  .segmented span { font-size: .8rem; }
  .history-list li { grid-template-columns: 27px minmax(0, 1fr) auto; gap: 6px; }
  .history-actions { flex-direction: column; }
  .rules { margin-top: 10px; padding: 12px 16px; border-radius: 14px; }
  .archive-panel { margin-top: 10px; padding: 12px 16px; }
}
@media (prefers-reduced-motion: no-preference) {
  .primary, .ghost, .icon-button, .segmented span { transition: background-color .16s ease, color .16s ease; }
}
