@layer reset, base, layout, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p { margin: 0; }
  button, input, textarea { font: inherit; }
  button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
  button { cursor: pointer; }
  button:disabled { cursor: default; }
  [hidden] { display: none !important; }
}
@layer base {
  :root { color-scheme: light; --paper: #f7f7ef; --ink: #183c34; --muted: #60705d; --line: #dddfd3; --lime: #d7f583; --red: #bc463b; --table: #173c35; }
  html { touch-action: manipulation; }
  body { background: var(--paper); color: var(--ink); font-family: 'Noto Sans Thai', 'Leelawadee UI', Tahoma, sans-serif; font-size: 16px; font-weight: 600; line-height: 1.65; touch-action: manipulation; }
  a { color: inherit; text-underline-offset: 4px; }
  button { color: inherit; }
  button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid #b2761f; outline-offset: 5px; }
  ::selection { background: var(--lime); color: var(--ink); }
  .screen-reader-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
}
@layer layout {
  .page-shell { max-width: 1280px; padding: 0 54px; margin: auto; }
  .site-header { height: 100px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); gap: 20px; }
  .intro { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 41px 0 30px; }
  .game-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 24px; align-items: start; }
  .table-panel { position: relative; background: var(--table); color: #edf4db; border-radius: 20px; padding: 25px 30px 19px; overflow: hidden; }
  .right-column { display: grid; gap: 15px; }
  .history-section { padding: 32px 0 26px; }
  .site-footer { border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 23px 0 30px; color: var(--muted); font-size: 12px; }
}
@layer components {
  .brand { font-size: 31px; font-weight: 800; letter-spacing: -1.8px; text-decoration: none; display: flex; align-items: center; gap: 8px; font-family: Arial, sans-serif; }
  .brand-mark { font-size: 34px; font-weight: 400; margin-right: 3px; }
  .brand-dot { margin-left: -7px; color: #879d34; }
  .header-caption { font-size: 10px; font-weight: 600; letter-spacing: 2.1px; color: var(--muted); }
  .button { min-height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 12px; border: 1px solid transparent; border-radius: 9px; padding: 10px 18px; font-weight: 800; touch-action: manipulation; transition: background-color 150ms, transform 150ms; }
  .button:hover:not(:disabled) { transform: translateY(-1px); }
  .button-small { min-height: 44px; padding: 7px 13px; font-size: 15px; }
  .button-outline { border-color: #cdd3c4; background: transparent; }
  .button-outline:hover:not(:disabled) { background: #e9eddf; }
  .button-lime { background: var(--lime); color: #173c35; font-size: 22px; }
  .button-lime:hover:not(:disabled) { background: #e1ffa0; }
  .button-lime:disabled { background: #b5cba3; color: #284a3f; }
  .button-dark { background: var(--ink); color: #fffef7; }
  .button-dark:hover:not(:disabled) { background: #295648; }
  .button-table { background: transparent; border-color: #577167; color: #f0f3e4; padding-inline: 16px; }
  .button-table:hover { background: #254e43; }
  .button:disabled { opacity: .65; }
  .eyebrow { font-family: Arial, sans-serif; font-size: 10px; font-weight: 600; letter-spacing: 1.8px; line-height: 1.5; color: var(--muted); display: flex; align-items: center; gap: 8px; }
  .live-dot { display: inline-block; width: 6px; height: 6px; background: #8baf52; border-radius: 50%; flex: 0 0 auto; }
  h1 { font-size: clamp(30px, 3.3vw, 42px); line-height: 1.45; letter-spacing: -1.3px; font-weight: 800; margin-top: 10px; }
  .intro-serif { font-weight: 700; }
  .intro-description { color: var(--muted); margin-top: 5px; font-size: 16px; }
  .mode-picker { display: inline-flex; background: #eaece2; border: 1px solid #e2e5d8; padding: 4px; border-radius: 10px; flex-shrink: 0; }
  .mode-picker button { background: transparent; border: 0; border-radius: 7px; padding: 9px 15px; font-size: 15px; font-weight: 700; color: #5c6856; }
  .mode-picker button[aria-pressed='true'] { background: #fffef8; color: var(--ink); box-shadow: 0 1px 4px #28361e0d; }
  .table-topline, .section-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .table-label { font-family: Arial, sans-serif; font-size: 11px; letter-spacing: 1.5px; color: #ceddba; }
  .deck-count { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: #cad9c5; white-space: nowrap; }
  .deck-count strong { font-size: 20px; color: #f2f8e7; font-weight: 800; }
  .deck-count .live-dot { background: var(--lime); width: 5px; height: 5px; }
  .card-stage { height: 352px; position: relative; display: grid; place-items: center; }
  .card-stage::before { content: ''; position: absolute; width: 340px; height: 340px; border: 1px solid #567d622e; border-radius: 50%; }
  .card-stage::after { content: ''; position: absolute; width: 395px; height: 395px; border: 1px solid #567d621c; border-radius: 50%; pointer-events: none; }
  .table-decoration { position: absolute; font-family: Georgia, serif; font-size: 67px; color: #76957323; user-select: none; }
  .decoration-left { left: 3%; bottom: 58px; transform: rotate(-20deg); }
  .decoration-right { right: 4%; top: 45px; transform: rotate(16deg); }
  .deck-stack { position: relative; width: 204px; height: 284px; isolation: isolate; }
  .deck-stack::before, .deck-stack::after { content: ''; position: absolute; inset: 0; border-radius: 12px; border: 1px solid #cfd4c1; background: #e9edda; z-index: -1; transform: translate(4px, 5px) rotate(3deg); transition: opacity 150ms; }
  .deck-stack::before { transform: translate(8px, 9px) rotate(6deg); background: #cbd5be; }
  .deck-stack.exhausted::before, .deck-stack.exhausted::after { opacity: 0; }
  .playing-card { position: relative; display: block; width: 100%; height: 100%; padding: 0; border: 7px solid #fffdf0; border-radius: 12px; box-shadow: 0 14px 27px #071f2a47; user-select: none; touch-action: manipulation; }
  .playing-card:disabled { cursor: default; }
  .playing-card:focus-visible { outline-color: var(--lime); }
  .card-back { color: #f2ebbf; background-color: #476555; background-image: repeating-linear-gradient(45deg, #c3d5a412 0px, #c3d5a412 1px, transparent 1px, transparent 7px), repeating-linear-gradient(-45deg, #c3d5a412 0px, #c3d5a412 1px, transparent 1px, transparent 7px); }
  .back-border { position: absolute; inset: 8px; border: 1px solid #ced8a98c; border-radius: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
  .back-title { font-family: Georgia, serif; font-size: 42px; font-weight: 700; letter-spacing: 2px; line-height: .95; text-align: center; white-space: pre-line; margin: 14px 0 15px; transform: rotate(-6deg); }
  .back-star { font-size: 35px; line-height: 1; }
  .back-star-small { font-size: 19px; margin-top: 18px; }
  .back-caption { font-family: Arial, sans-serif; font-size: 5.6px; letter-spacing: 1px; }
  .card-face { background: #fffdf3; color: #233d35; }
  .red { color: var(--red); }
  .card-corner { position: absolute; font-family: Georgia, serif; font-size: 30px; font-weight: 700; display: flex; flex-direction: column; line-height: .95; align-items: center; }
  .corner-top { left: 8px; top: 9px; }
  .corner-bottom { right: 8px; bottom: 9px; transform: rotate(180deg); }
  .corner-suit { font-size: 24px; margin-top: 4px; }
  .card-center { position: absolute; inset: 25px 33px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(5, 1fr); align-items: center; justify-items: center; font-family: Georgia, serif; font-size: 29px; line-height: 1; }
  .pip-inverted { transform: rotate(180deg); }
  .ace-pip { font-size: 65px; }
  .court-card { display: flex; flex-direction: column; justify-content: center; gap: 6px; border: 1px solid #b99a5a55; }
  .court-rank { font-size: 77px; line-height: 1; }
  .court-suit { font-size: 34px; }
  .court-ornament { color: #ac9354; font-size: 26px; }
  .table-hint { text-align: center; font-size: 15px; font-weight: 700; color: #d0dfc8; min-height: 25px; margin: 0 0 19px; }
  .draw-controls { display: flex; gap: 10px; position: relative; }
  .draw-controls .button-lime { flex: 1; min-width: 0; justify-content: space-between; padding-inline: 18px; }
  .table-bottomline { display: flex; align-items: center; justify-content: space-between; font-size: 9px; letter-spacing: 1px; color: #aec4ad; margin-top: 17px; }
  .table-bottomline span:last-child { letter-spacing: 0; }
  kbd { border: 1px solid #66836f; border-radius: 3px; padding: 1px 5px; margin-left: 5px; }
  .rule-panel { border: 1px solid var(--line); border-radius: 17px; background: #fffef8; padding: 24px; min-height: 307px; display: flex; flex-direction: column; align-items: start; }
  .section-topline { width: 100%; }
  .tiny-badge { border: 1px solid #dce1ce; color: #5a6c53; border-radius: 5px; padding: 3px 7px; font-size: 12px; font-weight: 700; font-family: Arial, Tahoma, sans-serif; letter-spacing: .5px; white-space: nowrap; }
  .rule-icon { width: 52px; height: 52px; background: #edf0dd; border: 1px solid #e2e7d3; border-radius: 50%; font-size: 32px; display: grid; place-items: center; line-height: 1; margin: 24px 0 15px; font-family: Georgia, serif; }
  .rule-panel h2 { font-size: 32px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 9px; line-height: 1.45; }
  .rule-panel > p { color: var(--ink); font-size: 20px; font-weight: 700; line-height: 1.75; }
  .rule-footnote { border-top: 1px solid #eaecde; padding-top: 14px; margin-top: 20px; font-size: 14px; font-weight: 700; color: #61724f; width: 100%; }
  .rule-footnote span { margin-right: 7px; }
  .bathroom-panel { display: flex; gap: 12px; align-items: center; border: 1px solid #d8dfc6; background: #edf1e1; padding: 17px; border-radius: 13px; }
  .bathroom-icon { font-family: Georgia, serif; font-size: 30px; color: #617c46; border: 1px dashed #a3b48a; border-radius: 7px; width: 35px; height: 46px; display: grid; place-items: center; flex-shrink: 0; }
  .bathroom-copy { flex: 1; }
  .bathroom-copy h3 { font-size: 16px; font-weight: 800; }
  .bathroom-copy p { font-size: 14px; color: #5e6d51; margin-top: 2px; }
  .bathroom-copy h3 span { display: inline-grid; place-items: center; min-width: 24px; height: 24px; background: #d5dfbf; border-radius: 5px; margin-left: 4px; }
  .bathroom-panel .button { padding-inline: 11px; min-height: 34px; white-space: nowrap; }
  .house-note { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--muted); padding: 4px 10px; }
  .house-note strong { color: #496044; font-weight: 800; }
  .note-star { color: #8b9e47; font-size: 30px; }
  .history-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
  .history-heading h2 { font-size: 21px; font-weight: 800; }
  .history-heading h2 span { margin-left: 9px; font-size: 15px; font-weight: 700; color: var(--muted); }
  .history-heading > p { font-size: 13px; color: var(--muted); }
  .history-list { display: flex; overflow-x: auto; gap: 9px; padding: 2px 1px 12px; list-style: none; margin: 0; min-height: 84px; scrollbar-width: thin; scrollbar-color: #c3cfb2 transparent; }
  .history-card { flex: 0 0 47px; height: 67px; border: 1px solid #d9dfcf; background: #fffdf6; border-radius: 6px; padding: 6px; display: flex; flex-direction: column; align-items: center; font-size: 18px; line-height: 1; font-family: Georgia, serif; position: relative; }
  .history-card:first-child { border-color: #81975f; background: #f1f7e2; }
  .history-card-rank { font-size: 19px; font-weight: 700; margin-bottom: 3px; }
  .history-number { font-family: Arial, sans-serif; font-size: 7px; color: #667458; margin-top: auto; }
  .history-empty { width: 100%; border: 1px dashed #d2d9c5; border-radius: 9px; color: #64715d; font-size: 12px; min-height: 67px; display: grid; place-items: center; padding: 12px; }
  .notice { min-height: 0; color: #657654; font-size: 11px; padding-bottom: 16px; }
  .notice:empty { padding: 0; }
  .footer-brand { font-family: Arial, sans-serif; font-weight: 700; font-size: 16px; letter-spacing: -.7px; color: #4e6855; }
  .site-footer a { text-decoration: none; font-size: 11px; }
  .site-footer a:hover { text-decoration: underline; }
  dialog { border: 1px solid #d6ddc9; border-radius: 18px; color: var(--ink); background: var(--paper); padding: 28px; width: min(650px, calc(100% - 30px)); max-height: calc(100dvh - 50px); box-shadow: 0 24px 90px #0a261e3d; }
  dialog::backdrop { background: #102d27a6; backdrop-filter: blur(5px); }
  .dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
  .dialog-header h2 { font-size: 28px; margin-top: 5px; font-weight: 800; }
  .dialog-description, #restart-dialog > p { font-size: 16px; color: var(--muted); }
  .icon-button { border: 1px solid #d5dcc8; background: transparent; border-radius: 50%; width: 36px; height: 36px; font-size: 25px; line-height: 1; flex-shrink: 0; }
  .rule-fields { display: grid; gap: 15px; margin-top: 22px; }
  .rule-field { display: grid; gap: 6px; }
  .rule-field-label { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 800; }
  .rule-rank { min-width: 41px; padding: 2px 7px; background: #e7ecd9; text-align: center; border-radius: 4px; font-weight: 600; }
  .rule-field textarea { width: 100%; padding: 10px 12px; resize: vertical; min-height: 75px; border: 1px solid #d1d8c4; border-radius: 7px; background: #fffef8; color: var(--ink); font-size: 18px; font-weight: 600; }
  .rules-source { margin-top: 20px; font-size: 11px; color: var(--muted); }
  .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 22px; }
  #restart-dialog { max-width: 440px; }
  .noscript { background: #f3e6be; text-align: center; padding: 20px; }
}
@layer responsive {
  @media (min-width: 1500px) { .page-shell { padding-top: 20px; } .intro { padding-top: 55px; } }
  @media (max-width: 1000px) { .page-shell { padding-inline: 28px; } .header-caption { font-size: 9px; letter-spacing: 1.2px; } .game-layout { gap: 18px; grid-template-columns: minmax(0, 1.2fr) minmax(290px, 1fr); } .table-panel { padding-inline: 22px; } .rule-panel { padding: 21px; } .intro { align-items: start; } .mode-picker { margin-top: 28px; } }
  @media (max-width: 760px) {
    .page-shell { padding-inline: 20px; }
    .site-header { height: 78px; }
    .header-caption { display: none; }
    .brand { font-size: 28px; }
    .intro { display: block; padding: 27px 0 23px; }
    h1 { font-size: 34px; }
    .mode-picker { margin-top: 20px; }
    .game-layout { grid-template-columns: 1fr; }
    .card-stage { height: 333px; }
    .table-panel { padding: 22px 24px 18px; }
    .draw-controls .button-lime { font-size: 20px; padding-inline: 14px; gap: 8px; }
    .button-table { font-size: 15px; padding-inline: 12px; gap: 6px; }
    .right-column { gap: 13px; }
    .rule-panel { min-height: auto; padding: 20px 22px; }
    .rule-icon { width: 41px; height: 41px; font-size: 26px; margin: 14px 0 10px; }
    .rule-panel h2 { font-size: 30px; }
    .rule-panel > p { font-size: 20px; }
    .rule-footnote { margin-top: 15px; }
    .bathroom-panel { padding: 17px 20px; }
    .house-note { padding: 5px 12px; }
    .history-section { padding-top: 25px; }
    .site-footer { flex-wrap: wrap; gap: 10px; }
    .site-footer > span:nth-child(2) { font-size: 12px; }
    .site-footer a { margin-left: auto; }
  }
  @media (max-width: 380px) {
    .page-shell { padding-inline: 14px; }
    h1 { font-size: 30px; }
    .table-panel { padding-inline: 17px; }
    .draw-controls { gap: 7px; }
    .draw-controls .button-lime { font-size: 20px; }
    .draw-controls .button-lime > span[aria-hidden] { display: none; }
    .table-label { letter-spacing: .5px; font-size: 10px; }
    .deck-count { gap: 4px; }
    .dialog-actions { flex-wrap: wrap; }
    .bathroom-panel { gap: 9px; padding-inline: 13px; flex-wrap: wrap; }
    .bathroom-copy { min-width: 180px; }
    .site-footer a { margin-left: 0; }
  }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
}
