/* Shared appearance tokens. Classic keeps the original component styling. */
:root {
  --theme-panel: #14291c;
  --theme-input: #0d1f12;
  --theme-edge: #b3c692;
  --theme-line: #5c3d1a;
  --theme-on-accent: #0d1f12;
  --theme-shadow: #080d09;
  --theme-title: #c9a84c;
  --theme-title-end: #314e29;
  --theme-title-text: #e8e0d0;
  --theme-overlay: rgba(0, 0, 0, 0.65);
  --theme-bevel-light: #fffdfc;
  --theme-bevel-dark: #b292a3;
}

html[data-theme="win95"]:root {
  color-scheme: light;
  --bg-deep: #f0dcd1;
  --felt: #e4afa9;
  --felt-subtle: #f2cec0;
  --wood: #b78e82;
  --gold: #9b5261;
  --gold-glow: rgba(155, 82, 97, 0.12);
  --cream: #553a37;
  --smoke: #795a51;
  --danger: #ab3e4a;
  --success: #246d59;
  --card-white: #fff2df;
  --font-display: Tahoma, "SimSun", "Microsoft YaHei", sans-serif;
  --font-body: Tahoma, "Microsoft YaHei", sans-serif;
  --theme-panel: #ecd4c7;
  --theme-input: #f5e5d5;
  --theme-edge: #89525b;
  --theme-line: #b78e82;
  --theme-on-accent: #fff3e3;
  --theme-shadow: #c49b8c;
  --theme-title: #d69099;
  --theme-title-end: #e7b1a9;
  --theme-title-text: #573135;
  --theme-overlay: rgba(85, 58, 55, 0.34);
  --theme-bevel-light: #fff0dd;
  --theme-bevel-dark: #b78e82;
}

/* Keep the stored neon identifier so existing selections open the new palette. */
html[data-theme="neon"]:root {
  color-scheme: light;
  --bg-deep: #dbe7ed;
  --felt: #b5d5bd;
  --felt-subtle: #d4e5c7;
  --wood: #91aca0;
  --gold: #356f62;
  --gold-glow: rgba(53, 111, 98, 0.12);
  --cream: #344c49;
  --smoke: #586e65;
  --danger: #a54b4f;
  --success: #356f62;
  --card-white: #fff5e0;
  --theme-panel: #cfdfdc;
  --theme-input: #e9eadb;
  --theme-edge: #416a5f;
  --theme-line: #91aca0;
  --theme-on-accent: #fff7e6;
  --theme-shadow: #a6bdb1;
  --theme-title: #b7d4da;
  --theme-title-end: #c5dacb;
  --theme-title-text: #365450;
  --theme-overlay: rgba(52, 76, 73, 0.34);
}

html[data-theme="peacock"] {
  color-scheme: dark;
  --bg-deep: #081a18;
  --felt: #075c56;
  --felt-subtle: #128078;
  --wood: #8e713e;
  --gold: #efc67b;
  --gold-glow: rgba(239, 198, 123, 0.15);
  --cream: #f1eee4;
  --smoke: #b4ccc4;
  --danger: #f4a69b;
  --success: #83dfb6;
  --theme-panel: #152d28;
  --theme-input: #0b221e;
  --theme-edge: #63e6ba;
  --theme-line: #8e713e;
  --theme-on-accent: #081a18;
  --theme-shadow: #040e0c;
}

html[data-theme="purple"] {
  color-scheme: dark;
  --bg-deep: #10051f;
  --felt: #63158f;
  --felt-subtle: #a82be1;
  --wood: #9d46d6;
  --gold: #fd63f6;
  --gold-glow: rgba(253, 99, 246, 0.15);
  --cream: #fff3ff;
  --smoke: #d7b8eb;
  --danger: #ff9eb9;
  --success: #a1e8cf;
  --theme-panel: #28103d;
  --theme-input: #1b092c;
  --theme-edge: #d2afff;
  --theme-line: #9d46d6;
  --theme-on-accent: #10051f;
  --theme-shadow: #080212;
}

html[data-theme="classic"] { color-scheme: dark; }

/* New themes use CSS scenery on both WebView and desktop. */
html[data-theme]:not([data-theme="classic"]) #room3dCanvas { display: none; }
html[data-theme]:not([data-theme="classic"]) .css-fallback-bg {
  background:
    radial-gradient(ellipse at 50% 43%, color-mix(in srgb, var(--theme-edge) 10%, transparent), transparent 62%),
    radial-gradient(ellipse at 85% 10%, var(--gold-glow), transparent 52%),
    repeating-linear-gradient(90deg, transparent 0 79px, color-mix(in srgb, var(--gold) 7%, transparent) 79px 80px),
    var(--bg-deep);
}
html[data-theme="peacock"] .css-fallback-bg {
  background:
    radial-gradient(ellipse at 50% 43%, rgba(99, 230, 186, 0.13), transparent 60%),
    repeating-linear-gradient(60deg, transparent 0 79px, rgba(239, 198, 123, 0.05) 79px 80px),
    repeating-linear-gradient(-60deg, transparent 0 79px, rgba(239, 198, 123, 0.05) 79px 80px), var(--bg-deep);
}
html:is([data-theme="win95"], [data-theme="neon"]):root :is(.css-fallback-bg, .account-screen, .login-screen) {
  background: var(--bg-deep);
}
html:is([data-theme="win95"], [data-theme="neon"]):root .card-front {
  background: var(--card-white);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--card-white) 80%, transparent),
    inset 0 -1px 0 color-mix(in srgb, var(--theme-shadow) 20%, transparent);
}
html:is([data-theme="win95"], [data-theme="neon"]):root .card-front::after {
  background: linear-gradient(180deg, transparent 62%, color-mix(in srgb, var(--theme-shadow) 8%, transparent));
}
html[data-theme]:not([data-theme="classic"]) .poker-table {
  border-color: var(--theme-panel);
  box-shadow: inset 0 0 55px color-mix(in srgb, var(--theme-shadow) 65%, transparent),
    inset 0 0 0 8px var(--theme-panel), 0 0 0 2px var(--wood),
    0 0 0 4px color-mix(in srgb, var(--gold) 65%, var(--bg-deep)),
    0 0 28px var(--gold-glow), 0 10px 28px color-mix(in srgb, var(--theme-shadow) 80%, transparent);
}
html[data-theme]:not([data-theme="classic"]) .poker-table::after {
  inset: 12px;
  border-color: color-mix(in srgb, var(--theme-edge) 42%, transparent);
}
html[data-theme]:not([data-theme="classic"]) .table-brand {
  color: var(--cream);
  opacity: 0.16;
}
html[data-theme]:not([data-theme="classic"]) .top-bar {
  background: linear-gradient(180deg, var(--theme-panel), color-mix(in srgb, var(--bg-deep) 90%, transparent));
}

/* Opaque surfaces replace the old hardcoded green panels in all views. */
html[data-theme]:not([data-theme="classic"]) :is(
  .account-form, .login-card, .mode-feedback-bar, .mode-feedback-pill, .mode-select-inline, .mode-link,
  .room-selection-summary, .room-card, .mode-choice-card,
  .player-info, .player-turn-timer, .npc-chat-bubble, .log-toggle, .log-body,
  .result-content, .npc-panel-content, .lb-content, .replay-content, .history-content, .history-table th,
  .hint-content, .eq-rules-box, .eq-side-btn, .eq-side-detail,
  .raise-quick-bar, .raise-quick-btn, .raise-quick-toggle, .raise-amount-wrap, .actions-panel,
  .tournament-banner, .settlement-banner, .menu-dropdown,
  .app-dialog-content, .avatar-viewer-card, .history-total-row
) {
  color: var(--cream);
  background: var(--theme-panel);
  border-color: var(--theme-line);
}
html[data-theme]:not([data-theme="classic"]) :is(
  .form-group input, .form-group select, .seat-swap-select,
  .app-dialog-input, .raise-input, .raise-input-container, .account-avatar, #avatarViewerImage
) {
  background: var(--theme-input);
  color: var(--cream);
  border-color: var(--theme-line);
}
html[data-theme]:not([data-theme="classic"]) input::placeholder { color: var(--smoke); opacity: 0.8; }
html[data-theme]:not([data-theme="classic"]) .card-back {
  background: radial-gradient(circle at 30% 24%, var(--gold-glow), transparent 40%),
    linear-gradient(180deg, var(--felt-subtle), var(--felt));
  border-color: var(--wood);
}
html[data-theme]:not([data-theme="classic"]) .card-back::after { border-color: var(--wood); }
html[data-theme]:not([data-theme="classic"]) .card-slot {
  background: color-mix(in srgb, var(--felt) 75%, var(--theme-panel));
  border-color: var(--wood);
}
html[data-theme]:not([data-theme="classic"]) .player-seat.active-turn .player-info {
  border-color: var(--theme-edge);
  box-shadow: 0 0 16px color-mix(in srgb, var(--theme-edge) 30%, transparent);
}
html[data-theme]:not([data-theme="classic"]) .player-turn-timer::after { background: var(--theme-edge); }
html[data-theme]:not([data-theme="classic"]) :is(.player-ledger, .player-bet-badge, .settlement-winner-line) { color: var(--gold); }
html[data-theme]:not([data-theme="classic"]) :is(.player-ready-badge, .player-auto-badge, .ready-status.ready-cancel, .btn-ready-toggle.ready, .result-showdown-winners, .settlement-amount, .history-positive, .account-create-status) { color: var(--success); }
html[data-theme]:not([data-theme="classic"]) :is(.account-error, .account-logout-btn, .allin-indicator, .player-totalbet, .history-negative) { color: var(--danger); }
html[data-theme]:not([data-theme="classic"]) :is(.room-card-name-en, .room-card-sub, .room-status-tag, .panel-empty, .settlement-refund-line, .dalio-attribution) { color: var(--smoke); }
html[data-theme]:not([data-theme="classic"]) :is(.settlement-pot-line, .settlement-details) { color: var(--cream); }
html[data-theme]:not([data-theme="classic"]) :is(.pot-amount, .settlement-details, .settlement-winner-line, .settlement-amount) { text-shadow: none; }
html[data-theme]:not([data-theme="classic"]) :is(.player-host-badge, .player-bet-badge, .room-status-tag) {
  border-color: var(--theme-line);
  background: var(--gold-glow);
}
html[data-theme]:not([data-theme="classic"]) :is(.action-fold, .action-check, .action-call) { background: var(--theme-panel); color: var(--cream); }
html[data-theme]:not([data-theme="classic"]) .action-raise { background: var(--gold); color: var(--theme-on-accent); }
html[data-theme]:not([data-theme="classic"]) .action-allin { background: var(--danger); color: var(--bg-deep); }
html[data-theme]:not([data-theme="classic"]) :is(.actions-panel, .actions-main) { color: var(--cream); }
html[data-theme]:not([data-theme="classic"]) :is(.action-btn, .btn-start-game, .btn-enter, .mode-back-btn, .owner-room-btn, .btn-quick) {
  background: var(--theme-panel);
  color: var(--cream);
  border-color: var(--theme-line);
}
html[data-theme]:not([data-theme="classic"]) :is(.btn-raise, .btn-enter, .owner-room-btn-primary) {
  background: var(--gold);
  color: var(--theme-on-accent);
  border-color: var(--gold);
}
html[data-theme]:not([data-theme="classic"]) .btn-call {
  background: color-mix(in srgb, var(--theme-edge) 15%, var(--theme-panel));
  border-color: var(--theme-edge);
  color: var(--cream);
}
html[data-theme]:not([data-theme="classic"]) .btn-allin { color: var(--danger); border-color: var(--danger); }
html[data-theme]:not([data-theme="classic"]) :is(.room-card.selected, .mode-link.active) { background: var(--gold-glow); border-color: var(--gold); color: var(--gold); }
html[data-theme]:not([data-theme="classic"]) .mode-link { --mode-accent: var(--theme-edge); }
html[data-theme]:not([data-theme="classic"]).compact-table .actions-main .raise-input { background: var(--theme-input); border-color: var(--theme-line); }
html[data-theme]:not([data-theme="classic"]).compact-table .actions-panel > .btn-allin { color: var(--danger); background: var(--theme-panel); border-color: var(--danger); }

/* Mint uses a pale blue header and quiet sage rail instead of neon lighting. */
html[data-theme="neon"]:root .poker-table {
  box-shadow: inset 0 0 0 8px var(--theme-panel),
    inset 0 0 25px color-mix(in srgb, var(--theme-shadow) 45%, transparent),
    0 0 0 2px var(--theme-line), 0 8px 20px color-mix(in srgb, var(--theme-shadow) 60%, transparent);
}
html[data-theme="neon"]:root :is(.poker-table-wrapper::before, .poker-table-wrapper::after) { opacity: 0.12; }
html[data-theme="neon"]:root .top-bar { background: linear-gradient(90deg, var(--theme-title), var(--theme-title-end)); }
html[data-theme="neon"]:root :is(.top-bar-title, .top-bar-info, .top-btn, .top-bar .speed-btn, .top-bar .pause-btn) { color: var(--theme-title-text); }

/* Win95: warm peach controls, inset inputs, pink title strips, square windows. */
html[data-theme="win95"]:root :is(
  .account-form, .login-card, .mode-feedback-bar, .mode-select-inline, .mode-link, .room-selection-summary,
  .room-card, .player-info, .result-content, .npc-panel-content,
  .lb-content, .replay-content, .history-content, .hint-content, .eq-rules-box, .eq-side-btn,
  .eq-side-detail, .raise-quick-bar, .menu-dropdown, .avatar-viewer-card,
  .theme-dialog
) {
  border-radius: 0;
  box-shadow: inset 1px 1px var(--theme-bevel-light), inset -1px -1px var(--theme-bevel-dark), 1px 2px var(--theme-shadow);
}
html[data-theme="win95"]:root :is(.card, .card-front, .card-front::before, .card-front::after, .card-back) { border-radius: 1px; }
html[data-theme="win95"]:root .poker-table {
  border-color: var(--theme-panel);
  box-shadow: inset 0 0 0 8px var(--theme-panel), inset 0 0 25px var(--theme-shadow),
    0 0 0 2px var(--theme-bevel-light), 0 0 0 4px var(--theme-line), 3px 7px var(--theme-shadow);
}
html[data-theme="win95"]:root .poker-table::after { border-color: var(--theme-line); }
html[data-theme="win95"]:root :is(.poker-table-wrapper::before, .poker-table-wrapper::after) { opacity: 0.12; }
html[data-theme="win95"]:root .top-bar {
  background: linear-gradient(90deg, var(--theme-title), var(--theme-title-end));
  box-shadow: inset 1px 1px var(--theme-bevel-light), 0 2px var(--theme-bevel-dark);
}
html[data-theme="win95"]:root :is(.top-bar-title, .top-bar-info, .top-btn, .top-bar .speed-btn, .top-bar .pause-btn) { color: var(--theme-title-text); }
html[data-theme="win95"]:root .top-bar-title { letter-spacing: 0.04em; }
html[data-theme="win95"]:root :is(.action-btn, .btn-start-game, .btn-enter, .mode-back-btn, .owner-room-btn, .btn-quick, .menu-toggle, .raise-quick-btn, .raise-quick-toggle, .theme-choice, .theme-close) {
  border: 2px outset var(--theme-bevel-light);
  border-radius: 0;
  background: var(--theme-panel);
  color: var(--cream);
  box-shadow: 1px 1px var(--theme-bevel-dark);
}
html[data-theme="win95"]:root :is(.action-btn, .btn-start-game, .btn-enter, .mode-back-btn, .owner-room-btn, .btn-quick, .menu-toggle, .raise-quick-btn, .raise-quick-toggle, .theme-choice, .theme-close):active { border-style: inset; }
html[data-theme="win95"]:root :is(.btn-raise, .btn-enter, .owner-room-btn-primary) { background: var(--gold); color: var(--theme-on-accent); }
html[data-theme="win95"]:root .btn-call { background: var(--theme-input); color: var(--cream); }
html[data-theme="win95"]:root .btn-allin { color: var(--danger); }
html[data-theme="win95"]:root :is(.form-group input, .form-group select, .seat-swap-select, .app-dialog-input, .raise-input) { border: 2px inset var(--theme-bevel-light); border-radius: 0; }
html[data-theme="win95"]:root .player-seat.active-turn .player-info { border-color: var(--gold); box-shadow: inset 1px 1px var(--theme-bevel-light), 0 0 0 1px var(--gold); }
html[data-theme="win95"]:root .theme-dialog-heading { background: linear-gradient(90deg, var(--theme-title), var(--theme-title-end)); color: var(--theme-title-text); }
html[data-theme="win95"]:root .menu-dropdown .theme-menu-item { background: var(--gold); color: var(--theme-on-accent); }
html[data-theme="win95"]:root .theme-menu-item [data-current-theme] { color: var(--theme-on-accent); }

/* A solid label and double outline remain visible in light and dark palettes. */
html[data-theme]:root .player-seat.active-turn .player-turn-timer {
  color: var(--theme-on-accent);
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 2px 6px var(--theme-shadow);
}
html[data-theme]:root .player-seat.active-turn .player-turn-timer-text { color: inherit; }
html[data-theme]:root .player-seat.active-turn .player-turn-timer::after { background: currentColor; }
@media (max-width: 768px), (max-height: 500px) {
  .player-turn-label { font-size: 0.58rem; }
}

/* Theme chooser, shared by lobby, table, browser, and the existing Android host. */
.theme-menu-item [data-current-theme] { display: block; margin-top: 3px; color: var(--smoke); font-size: 0.65rem; }
.theme-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: var(--theme-overlay);
}
.theme-modal.hidden { display: none; }
.theme-dialog {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: var(--theme-panel);
  color: var(--cream);
  border: 1px solid var(--theme-line);
  border-radius: 10px;
  box-shadow: 0 14px 45px var(--theme-shadow);
}
.theme-dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: -12px -12px 14px; padding: 7px 10px; }
.theme-dialog-heading h2 { font-size: 1rem; font-weight: 600; }
.theme-dialog-heading button { min-height: 36px; padding: 5px 12px; font: inherit; font-size: 0.8rem; border: 1px solid var(--theme-line); border-radius: 4px; background: var(--theme-panel); color: var(--cream); cursor: pointer; }
.theme-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-choice {
  min-width: 0;
  min-height: 96px;
  padding: 11px;
  text-align: left;
  border: 1px solid var(--theme-line);
  border-radius: 6px;
  color: var(--cream);
  background: var(--theme-input);
  font: inherit;
  cursor: pointer;
}
.theme-choice[aria-pressed="true"] { outline: 2px solid var(--gold); outline-offset: -4px; }
.theme-choice:disabled { cursor: wait; opacity: 0.65; }
.theme-choice:focus-visible, .theme-dialog-heading button:focus-visible { outline: 2px solid var(--theme-edge); outline-offset: 2px; }
.theme-choice-colors { display: flex; height: 17px; margin-bottom: 8px; }
.theme-choice-colors span { flex: 1; }
.theme-choice-name { display: block; font-size: 0.84rem; font-weight: 600; }
.theme-choice[aria-pressed="true"] .theme-choice-name::after { content: " ✓"; color: var(--gold); }
.theme-choice-description { display: block; margin-top: 4px; font-size: 0.7rem; line-height: 1.4; color: var(--smoke); }
#themeSaveStatus { margin: 13px 0 0; color: var(--smoke); font-size: 0.75rem; line-height: 1.5; }
#themeSaveStatus.theme-save-error { color: var(--danger); }
@media (max-height: 500px) and (min-width: 600px) {
  .theme-dialog { width: min(720px, 100%); padding: 12px; }
  .theme-choices { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .theme-choice { min-height: 82px; padding: 8px; }
  .theme-choice-description { font-size: 0.68rem; }
  .theme-dialog-heading { margin-bottom: 8px; }
  #themeSaveStatus { margin-top: 9px; }
}
@media (pointer: coarse) {
  .theme-dialog-heading button { min-height: 44px; }
}
