@layer reset, base, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p { margin: 0; }
  button, input, select { font: inherit; }
  button, select { cursor: pointer; }
  button { color: inherit; }
  a { color: inherit; }
  button:disabled { cursor: default; }
  [hidden] { display: none !important; }
}

@layer base {
  :root { color-scheme: light; --green: #103f32; --ink: #173d32; --muted: #627568; --paper: #f7f8f3; --line: #dce3d9; --gold: #f1d291; --blue: #c8dfe5; --red: #a23e2d; }
  html { min-width: 320px; background: var(--paper); scroll-behavior: smooth; }
  body { min-height: 100svh; padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); background: var(--paper); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 1rem; line-height: 1.5; -webkit-font-smoothing: antialiased; }
  button { -webkit-tap-highlight-color: transparent; }
  button, input, select, a { touch-action: manipulation; }
  :focus-visible { outline: 3px solid #c18b26; outline-offset: 4px; }
  button:disabled { opacity: .43; }
  ::selection { background: #e8cf93; color: var(--green); }
  h1, h2, h3 { line-height: 1.15; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
  .skip-link { position: fixed; top: -90px; left: 16px; padding: 12px; z-index: 20; background: white; }
  .skip-link:focus { top: 10px; }
}

@layer components {
  .page-shell { max-width: 1256px; margin: 0 auto; padding: 0 48px; }
  .site-header { height: 108px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); gap: 16px; }
  .brand { display: inline-flex; gap: 11px; align-items: center; text-decoration: none; font-size: 2rem; font-weight: 800; letter-spacing: -1.5px; }
  .brand-period { color: #b28941; }
  .brand-mark { display: grid; place-items: center; width: 39px; height: 45px; border: 1.5px solid var(--green); border-radius: 7px; transform: rotate(-9deg); font-size: 1.65rem; line-height: 1; background: var(--green); color: var(--gold); box-shadow: 4px 3px 0 var(--paper), 5px 3px 0 1px var(--green); }
  .header-controls { display: flex; align-items: center; gap: 28px; }
  .button { display: inline-flex; min-height: 46px; align-items: center; justify-content: center; gap: 9px; padding: 10px 18px; border: 1px solid transparent; border-radius: 8px; font-size: .875rem; font-weight: 650; line-height: 1.4; background: transparent; text-decoration: none; transition: background .15s, transform .15s; }
  .header-new-game, .footer-rules { display: none; }
  .button:active:not(:disabled) { transform: translateY(1px); }
  .button .icon { flex: 0 0 auto; }
  .text-button { padding: 8px 0; }
  .outline { border-color: #b9c9b9; background: #ffffff60; }
  .primary { color: #fffef5; background: var(--green); min-height: 54px; }
  .primary:disabled { opacity: 1; color: #748579; background: #dfe6dc; }
  .subtle { color: var(--muted); }
  .language-wrap { position: relative; }
  .language-wrap select { appearance: none; -webkit-appearance: none; border: 1px solid #d5ded2; border-radius: 7px; padding: 10px 36px 10px 13px; min-height: 44px; color: var(--ink); background: transparent; font-size: .875rem; font-weight: 600; }
  .language-wrap > span { position: absolute; right: 12px; top: 8px; pointer-events: none; }
  .intro { padding: 49px 0 35px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
  .eyebrow { font-size: .75rem; font-weight: 750; letter-spacing: .15em; color: #61745f; }
  h1 { font-size: clamp(2.15rem, 3.8vw, 3rem); font-weight: 650; letter-spacing: -.055em; margin: 11px 0 12px; }
  .intro-copy { color: var(--muted); font-size: 1rem; }
  .game-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr); gap: 28px; align-items: start; }
  .game-column { min-width: 0; }
  .scoreboard { background: var(--green); color: #f5f6e8; border-radius: 16px; padding: 25px; position: relative; overflow: hidden; }
  .scoreboard::before { content: ''; pointer-events: none; position: absolute; width: 470px; height: 470px; top: -365px; left: 50px; border: 1px solid #ffffff0b; border-radius: 50%; box-shadow: 0 0 0 30px #ffffff03, 0 0 0 60px #ffffff02; }
  .board-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 29px; gap: 12px; position: relative; }
  .game-state { display: flex; align-items: center; gap: 8px; color: #e0e8d8; font-size: .875rem; }
  .state-dot { width: 6px; height: 6px; background: #b7ce9a; border-radius: 50%; }
  .state-dot.finished { background: var(--gold); }
  .board-target { font-size: .75rem; letter-spacing: .09em; color: #b8cdbb; white-space: nowrap; }
  .board-target strong { font-size: 1rem; color: var(--gold); margin-left: 6px; }
  .score-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .score-card { background: #ffffff07; border: 1px solid #ffffff20; border-radius: 11px; padding: 19px 19px 22px; min-width: 0; }
  .team-0 { --team-color: var(--gold); }
  .team-1 { --team-color: var(--blue); }
  .team-heading { display: flex; align-items: center; gap: 9px; }
  .team-emblem { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #ffffff0d; color: var(--team-color); font-size: 1.1rem; flex-shrink: 0; }
  .team-name { border: 0; background: none; padding: 4px 0; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; color: #f3f5e9; min-width: 0; overflow-wrap: anywhere; text-align: left; width: 100%; }
  .team-name .icon { width: 15px; flex-shrink: 0; opacity: .6; }
  .team-name-text { min-width: 0; }
  .big-score { color: var(--team-color); text-align: center; font-size: clamp(3.2rem, 7.7vw, 6.7rem); font-weight: 550; letter-spacing: -.065em; line-height: 1.1; padding: 29px 0 32px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  .score-bottom { display: flex; justify-content: space-between; gap: 6px; align-items: center; font-size: .875rem; color: #c6d8ca; }
  .score-bottom > span:first-child { display: flex; align-items: center; gap: 4px; }
  .score-bottom .icon { width: 14px; }
  .target-label { opacity: .8; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .progress-track { display: block; appearance: none; border: 0; border-radius: 5px; width: 100%; height: 4px; overflow: hidden; margin-top: 15px; background: #ffffff17; }
  .progress-track::-webkit-progress-bar { background: #ffffff17; border-radius: 5px; }
  .progress-track::-webkit-progress-value { background: var(--team-color); border-radius: 5px; transition: width .3s; }
  .progress-track::-moz-progress-bar { background: var(--team-color); border-radius: 5px; }
  .board-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; color: #c1d1c1; font-size: .875rem; flex-wrap: wrap; }
  .save-status { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; }
  .save-status .icon { width: 14px; height: 14px; }
  .table-note { display: flex; align-items: center; justify-content: center; gap: 15px; padding: 28px 8px; color: var(--muted); font-size: .875rem; }
  .table-note > span { letter-spacing: 4px; color: var(--green); white-space: nowrap; }
  .red-suit { color: #9c614f; }
  .round-panel { background: #fff; padding: 27px; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 5px 18px #173d3204; }
  .round-panel-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 22px; }
  .panel-kicker { font-size: .6875rem; font-weight: 700; letter-spacing: .08em; color: var(--muted); white-space: nowrap; }
  h2 { font-size: 1.45rem; letter-spacing: -.035em; font-weight: 650; }
  fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
  legend { font-size: .875rem; font-weight: 650; margin-bottom: 9px; padding: 0; }
  .team-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .team-option { min-height: 46px; padding: 9px 12px; border-radius: 7px; border: 1px solid var(--line); background: #fff; display: flex; gap: 7px; align-items: center; justify-content: center; font-size: .875rem; min-width: 0; }
  .team-option > span:nth-child(2) { overflow-wrap: anywhere; }
  .team-option > span:first-child { font-size: 1.2rem; }
  .team-option .icon { display: none; width: 15px; flex-shrink: 0; }
  .team-option.selected { background: #f0f3e9; border-color: var(--green); font-weight: 650; }
  .team-option.selected .icon { display: block; }
  .points-picker { margin-top: 20px; }
  .points-picker legend { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .points-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
  .points-option { border: 1px solid #d5ded0; border-radius: 8px; background: #fafbf7; color: var(--ink); min-height: 48px; font-size: 1.125rem; font-weight: 600; font-variant-numeric: tabular-nums; padding: 4px; }
  .points-option:active { background: #e5ecdf; border-color: #9aaf91; }
  .contract-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; min-height: 48px; }
  .switch-label { display: inline-flex; align-items: center; gap: 9px; font-size: .875rem; font-weight: 650; min-height: 44px; cursor: pointer; position: relative; flex-shrink: 0; }
  .switch-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }
  .switch-track { display: block; position: relative; width: 44px; height: 26px; border-radius: 20px; background: #c5d1bf; transition: background .15s; }
  .switch-track::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 3px #173d3233; transition: transform .15s; }
  .switch-label input:checked + .switch-track { background: var(--green); }
  .switch-label input:checked + .switch-track::before { transform: translateX(18px); }
  .switch-label input:focus-visible + .switch-track { outline: 3px solid #c18b26; outline-offset: 3px; }
  .penalty-summary { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; min-width: 0; max-width: 60%; padding: 5px 9px; background: #f9ede7; border: 1px solid #ead4c9; border-radius: 7px; font-size: .875rem; color: var(--red); }
  .penalty-summary > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .penalty-summary strong { white-space: nowrap; }
  .penalty-summary .icon { width: 14px; flex-shrink: 0; }
  .penalty-option { color: var(--red); background: #fcf8f4; }
  .penalty-option:active { background: #f9ede7; border-color: #b67a68; }
  .small-text { font-size: .875rem; color: var(--muted); line-height: 1.6; }
  .round-preview { background: #f3f5ef; border-radius: 8px; padding: 10px 14px; min-height: 48px; margin: 8px 0 12px; display: grid; align-items: center; }
  .preview-placeholder { color: var(--muted); font-size: .875rem; }
  .preview-scores { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .preview-scores > div { display: flex; gap: 5px; align-items: center; justify-content: space-between; min-width: 0; }
  .preview-scores > div + div { border-left: 1px solid var(--line); padding-left: 15px; }
  .preview-name { font-size: .875rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .preview-scores strong { font-size: 1.35rem; line-height: 1.2; letter-spacing: -.04em; font-weight: 650; white-space: nowrap; }
  .negative { color: var(--red); }
  .entry-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
  .autosave-note { color: var(--muted); font-size: .8125rem; }
  .history-section { margin: 39px 0 54px; }
  .section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
  .section-heading p { color: var(--muted); font-size: .875rem; margin-top: 7px; }
  .empty-history { display: flex; gap: 28px; align-items: center; padding: 32px 38px; border: 1px dashed #cbd6c6; border-radius: 11px; background: #f1f4ec; }
  .empty-history h3 { font-weight: 600; font-size: 1rem; margin-bottom: 6px; }
  .empty-history p { color: var(--muted); font-size: .875rem; }
  .mini-cards { position: relative; width: 64px; height: 65px; flex-shrink: 0; }
  .mini-cards span { position: absolute; width: 39px; height: 55px; border: 1px solid #b7c5ae; border-radius: 5px; background: #f9faf5; display: grid; place-items: center; font-size: 1.3rem; top: 3px; }
  .mini-cards span:first-child { transform: rotate(-15deg); left: 1px; color: var(--green); }
  .mini-cards span:last-child { transform: rotate(12deg); left: 23px; top: 6px; color: #ad7154; }
  .table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
  table { width: 100%; border-collapse: collapse; text-align: left; font-size: .875rem; min-width: 590px; }
  th { padding: 14px 19px; background: #eff3ea; color: var(--muted); font-weight: 600; font-size: .8125rem; overflow-wrap: anywhere; max-width: 150px; }
  td { padding: 16px 19px; border-top: 1px solid #e8ece3; max-width: 180px; }
  tbody tr:first-child { background: #fcfcf8; }
  .round-index { font-variant-numeric: tabular-nums; color: var(--muted); }
  .bid-team { display: flex; gap: 7px; align-items: baseline; font-weight: 600; overflow-wrap: anywhere; }
  .team-ink-0 { color: #9c701c; }
  .team-ink-1 { color: #427a83; }
  .table-secondary { display: block; font-size: .75rem; color: var(--muted); margin-top: 3px; }
  .numeric { text-align: right; font-variant-numeric: tabular-nums; }
  .delta { font-weight: 650; font-size: 1rem; white-space: nowrap; }
  .running-total { font-weight: 650; white-space: nowrap; }
  .running-total span { color: #879282; padding: 0 4px; }
  .result-tag { font-size: .75rem; display: inline-block; padding: 3px 8px; border-radius: 4px; white-space: nowrap; }
  .result-tag.made { color: #38644a; background: #edf3e6; }
  .result-tag.failed { color: #9c4234; background: #f9ede7; }
  .site-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 0 26px; border-top: 1px solid var(--line); }
  .site-footer > span { font-size: .625rem; letter-spacing: .16em; font-weight: 700; color: var(--muted); }
  .site-footer .button { font-size: .8125rem; color: var(--muted); }
  .site-footer .icon { width: 16px; }
  .notice { padding: 18px 22px; border: 1px solid #d7bc7c; background: #fff5d8; border-radius: 9px; margin-bottom: 24px; display: flex; align-items: center; gap: 20px; font-size: .875rem; }
  .notice .button { border: 1px solid #bea35f; flex-shrink: 0; }
  .winner-panel { text-align: center; min-height: 470px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fdfcf5; }
  .winner-medallion { width: 82px; height: 82px; display: grid; place-items: center; border-radius: 50%; background: #f0dfb0; color: #6b5429; margin-bottom: 25px; }
  .winner-medallion .icon { width: 38px; height: 38px; }
  .winner-panel h2 { margin: 12px 0; font-size: 2rem; overflow-wrap: anywhere; max-width: 100%; }
  .winner-panel > p:not(.eyebrow) { color: var(--muted); }
  .winner-panel .final-score { font-size: 1.25rem; margin: 18px 0 23px; font-variant-numeric: tabular-nums; }
  .winner-panel .button { width: 100%; }
  .winner-panel .small-text { margin-top: 18px; }
  dialog { border: 1px solid #d6dfd0; border-radius: 17px; padding: 36px; width: min(520px, calc(100% - 32px)); max-height: calc(100svh - 40px); overflow-y: auto; color: var(--ink); background: var(--paper); box-shadow: 0 20px 100px #07291f44; }
  dialog::backdrop { background: #062b22a6; backdrop-filter: blur(4px); }
  dialog h2 { font-size: 1.8rem; margin: 10px 24px 17px 0; }
  dialog > p { color: var(--muted); font-size: 1rem; margin-bottom: 17px; }
  .modal-close { position: absolute; top: 13px; right: 13px; display: grid; place-items: center; border: 0; border-radius: 50%; width: 40px; height: 40px; background: transparent; }
  .name-inputs { display: grid; gap: 17px; margin: 25px 0 12px; }
  .name-inputs label { font-weight: 600; font-size: .875rem; }
  .name-inputs input { margin-top: 6px; display: block; width: 100%; border: 1px solid #b6c8b3; border-radius: 7px; min-height: 49px; padding: 10px 13px; background: white; color: var(--ink); font-size: 1rem; }
  .modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 28px; }
  .modal-actions .button { min-height: 48px; }
  .rules-list { padding-left: 20px; color: var(--muted); }
  .rules-list li { padding-left: 5px; margin-bottom: 15px; }
  .source-link { display: inline-block; margin-top: 8px; font-weight: 600; text-underline-offset: 4px; font-size: .875rem; }
  .install-symbol { width: 52px; height: 52px; background: #e7eddc; border-radius: 12px; display: grid; place-items: center; }
  .install-symbol .icon { width: 25px; height: 25px; }
  .offline-readiness { padding: 13px 15px; border-radius: 7px; background: #f1e8cc; font-size: .875rem; margin: 20px 0; }
  .offline-readiness.is-ready { background: #e6eedb; }
}

@layer responsive {
  /* Touch browsers can keep :hover active after a tap. Only pointing devices
     get hover feedback; keyboard focus remains visible on every device. */
  @media (hover: hover) and (pointer: fine) {
    .button:hover:not(:disabled) { background: #e8ede3; }
    .text-button:hover:not(:disabled) { background: transparent; text-decoration: underline; text-underline-offset: 5px; }
    .primary:hover:not(:disabled) { background: #205942; }
    .team-name:hover { text-decoration: underline; text-underline-offset: 4px; }
    .team-option:hover { border-color: var(--green); }
    .modal-close:hover { background: #e5ebdf; }
  }
  @media (min-width: 1500px) { .page-shell { padding-top: 20px; } .intro { padding-top: 60px; padding-bottom: 45px; } }
  @media (max-width: 1050px) {
    .page-shell { padding: 0 28px; }
    .game-layout { gap: 20px; grid-template-columns: minmax(0, 1.3fr) minmax(320px, 1fr); }
    .scoreboard { padding: 20px; }
    .score-cards { gap: 10px; }
    .score-card { padding: 13px 13px 18px; }
    .round-panel { padding: 22px; }
    .big-score { font-size: 5rem; }
    .board-footer { flex-direction: column; gap: 6px; }
    .score-bottom { font-size: .75rem; }
  }
  @media (max-width: 760px) {
    .page-shell { max-width: 620px; padding: 0 14px; }
    .site-header { height: 60px; border-bottom: 0; gap: 8px; }
    .brand { font-size: 1.55rem; gap: 8px; }
    .brand-mark { width: 25px; height: 31px; font-size: 1.15rem; }
    .header-controls { gap: 8px; }
    .header-controls .rules-button { display: none; }
    .header-new-game { display: inline-flex; min-width: 44px; padding: 8px; border: 1px solid var(--line); }
    .language-wrap select { padding: 8px 30px 8px 11px; }
    .intro, .table-note { display: none; }
    .game-layout { grid-template-columns: 1fr; gap: 10px; }
    .scoreboard { padding: 10px 12px; border-radius: 11px; }
    .board-heading { margin-bottom: 7px; }
    .game-state { font-size: .75rem; }
    .board-target { font-size: .6875rem; }
    .board-target strong { font-size: .875rem; }
    .score-cards { gap: 9px; }
    .score-card { padding: 3px 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 7px; border-radius: 8px; }
    .team-heading { min-width: 0; }
    .team-emblem { display: none; }
    .team-name { font-size: .875rem; gap: 4px; overflow: hidden; }
    .team-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .team-name .icon { width: 12px; }
    .big-score { font-size: 2.45rem; line-height: 1.1; padding: 0; overflow-wrap: normal; }
    .score-bottom, .progress-track, .board-footer { display: none; }
    .round-panel { padding: 15px; border-radius: 11px; }
    .round-panel-heading { margin-bottom: 12px; }
    .round-panel-heading h2 { font-size: 1.2rem; }
    .panel-kicker { font-size: .625rem; letter-spacing: .04em; }
    legend { margin-bottom: 6px; }
    .team-option { min-height: 44px; padding: 7px 10px; }
    .team-option > span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .points-picker { margin-top: 12px; }
    .points-grid { gap: 6px; }
    .points-option { min-height: 44px; }
    .contract-row { margin-top: 4px; min-height: 44px; }
    .round-preview { min-height: 40px; padding: 7px 11px; margin: 4px 0 9px; }
    .preview-scores strong { font-size: 1.25rem; }
    .history-section { margin: 23px 0 30px; }
    .section-heading { align-items: flex-start; gap: 8px; margin-bottom: 15px; }
    .section-heading h2 { font-size: 1.2rem; }
    .section-heading p { max-width: 190px; font-size: .8125rem; }
    .undo-button { padding: 1px 0; font-size: .8125rem; min-height: 44px; }
    .undo-button .icon { width: 17px; }
    .empty-history { padding: 20px; gap: 19px; }
    .site-footer { padding: 12px 0 20px; gap: 12px; }
    .site-footer > span { display: none; }
    .footer-rules { display: inline-flex; }
    .notice { flex-direction: column; align-items: flex-start; gap: 10px; }
    .winner-panel { min-height: 340px; }
    .winner-panel .eyebrow { font-size: .75rem; }
  }
  @media (max-width: 360px) {
    .page-shell { padding: 0 10px; }
    .brand { font-size: 1.45rem; }
    .round-panel { padding: 12px; }
    .round-panel-heading { gap: 6px; }
    .round-panel-heading h2 { font-size: 1.1rem; }
    .empty-history { gap: 15px; padding: 18px 14px; }
    .mini-cards { transform: scale(.85); width: 53px; }
    .modal-actions { flex-wrap: wrap; }
    dialog { padding: 28px 22px; }
  }
  @media (max-width: 760px) and (max-height: 650px) {
    .site-header { height: 52px; }
    .round-panel { padding-top: 11px; padding-bottom: 8px; }
    .round-panel-heading { margin-bottom: 4px; }
    .team-picker > legend { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
    .points-picker { margin-top: 4px; }
    .points-grid { gap: 4px; }
    .round-preview { margin-top: 0; margin-bottom: 6px; }
  }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }
}
