/* Shared layout and appearance for game-control Web Components. */
/* The toolbar is centred in the space below the corner close button; a taller one scrolls instead of covering it. */
chess-toolbar {
  position: fixed;
  right: 1.5rem;
  top: var(--page-close-clear);
  bottom: .75rem;
  height: fit-content;
  max-height: calc(100dvh - var(--page-close-clear) - .75rem);
  margin-block: auto;
  overflow-y: auto;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
chess-button, chess-level, chess-spacer { display: block; margin-block: .15rem; }
.control-group { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.control-group > chess-button, .control-group > chess-level { margin: 0; }
chess-toolbar { gap: .5rem; padding: 4px; background: transparent; border: 0; box-shadow: none; }
chess-toolbar > chess-spacer { height: .3rem; margin: 0; }
.picker-tools .control-group, .pgn-card-actions .control-group { flex-direction: row; }
.picker-tools > chess-spacer { width: .65rem; height: var(--icon-btn-size); margin: 0; }
.pgn-card-actions > chess-spacer { width: .35rem; height: var(--icon-btn-size); margin: 0; }
chess-spacer { width: var(--icon-btn-size); height: var(--icon-btn-size); flex-shrink: 0; pointer-events: none; }
/* chess-button defaults to medium; game controls opt into large explicitly. */
chess-spacer[size="large"], chess-button[size="large"] { --icon-btn-size: 3.52rem; --icon-svg-size: 1.76rem; }
chess-spacer[size="medium"], chess-button, chess-button[size="medium"] {
  --icon-btn-size: 46px;
  --icon-svg-size: 23px;
}
chess-spacer[size="small"], chess-button[size="small"] {
  --icon-btn-size: 37.4px;
  --icon-svg-size: 19.8px;
}
chess-button[size="small"] .icon-btn {
  min-height: 0;
  box-shadow: 0 3px 7px rgba(var(--shell-shadow, 40, 30, 10), .18), inset 0 1px 0 rgba(255, 255, 255, .4);
}
chess-button[size="small"] .icon-btn svg { stroke-width: 1.65; }
chess-button[size="small"] .icon-btn:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }
/* The turn indicator bar sits below where the close button used to be. */
:root { --page-close-clear: calc(env(safe-area-inset-top, 0px) + .75rem + 44px + .5rem); }
/* The action bar is a full-height rail on the right edge: the close button on top, the controls centred below it; a taller bar scrolls. */
chess-toolbar:not(.board-turn-controls) {
  top: 0; right: 0; bottom: 0;
  height: auto; max-height: none; margin: 0;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + .75rem) calc(env(safe-area-inset-right, 0px) + .75rem) .75rem .75rem;
}
chess-toolbar:not(.board-turn-controls)::before, chess-toolbar:not(.board-turn-controls)::after { content: ""; flex: 1 0 0; }
chess-toolbar > chess-button.page-close { order: -1; }
chess-toolbar > chess-button.page-close + chess-spacer, chess-toolbar:has(> chess-button.page-close[hidden]:only-child) { display: none; }
/* The close button stays put while the rest of the bar scrolls (down the rail, along the row). */
chess-toolbar:not(.board-turn-controls) > chess-button.page-close { position: sticky; top: calc(env(safe-area-inset-top, 0px) + .75rem); z-index: 1; flex: none; }
chess-toolbar:not(.board-turn-controls) > .control-group[data-zone="top"] { order: -1; }
chess-toolbar:not(.board-turn-controls) > .control-group[data-zone="bottom"] { order: 1; }
/* The rail's bubbles open towards the page (the generic anchored tooltip in chess-button.css); the pointer sits on the rail side. */
@media (hover: hover) and (min-width: 1025px) and (min-height: 501px) {
  chess-toolbar:not(.board-turn-controls) chess-button[data-tooltip]::before,
  chess-toolbar:not(.board-turn-controls) chess-button[data-tooltip]::after { position-area: left; align-self: anchor-center; justify-self: unsafe end; }
  chess-toolbar:not(.board-turn-controls) chess-button[data-tooltip]::before { margin: 0 6px 0 0; }
  chess-toolbar:not(.board-turn-controls) chess-button[data-tooltip]::after { border: 6px solid transparent; border-right: 0; border-left-color: var(--ink, #334155); }
}
chess-appearance { display: contents; }
@media (min-width: 601px) { chess-appearance > chess-button[data-action="board-settings"] { display: none; } }
/* A thin-line gear keeps the settings button light. */
chess-appearance > chess-button[data-action="board-settings"] .icon-btn[data-variant] svg { stroke-width: 1.2; }
.control-group[hidden], chess-timer[hidden], chess-button[hidden], chess-level[hidden], chess-toolbar[hidden], chess-appearance[hidden], chess-spacer[hidden] { display: none; }
.icon-btn {
  width: var(--icon-btn-size);
  height: var(--icon-btn-size);
  box-sizing: border-box;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--accent-dark);
  background: var(--icon-btn-bg);
  box-shadow: 0 6px 14px rgba(var(--shell-shadow, 40, 30, 10), 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover {
  background: var(--icon-btn-bg-hover);
}
.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.icon-btn:disabled:hover {
  background: var(--icon-btn-bg);
}
/* Basılı yuvarlak düğme turuncu zeminini korur; chess-button.css'in açık basılı zemini beyaz ikonu görünmez yapıyordu. */
chess-button > button.icon-btn[aria-pressed="true"] {
  background: var(--icon-btn-bg);
}
/* Basılı durumun halkası diğer yuvarlak düğmelerde yok; klavye odak halkası korunur. */
chess-button > button.icon-btn[aria-pressed="true"]:not(:focus-visible) {
  outline: none;
}
chess-button > button.icon-btn[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--icon-btn-bg-hover);
}
.icon-btn svg {
  display: block;
  flex-shrink: 0;
  width: var(--icon-svg-size);
  height: var(--icon-svg-size);
  stroke-width: 1.8;
  stroke: var(--icon-fg);
  fill: none;
}
.icon-btn svg .board-dark-squares { fill: var(--icon-fg); stroke: none; }

chess-toolbar .icon-btn:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 4px; }
.icon-btn[data-icon="hint"] svg, .icon-btn[data-icon="profile"] svg { fill: var(--icon-fg); stroke: none; }
.icon-btn[data-icon="refresh"]:hover svg { transform: rotate(-25deg); }
.level-bar { fill: none; stroke: var(--icon-fg); stroke-width: .7; opacity: .5; transition: opacity .15s ease; }
.level-bar.filled { fill: var(--icon-fg); opacity: 1; }
.level-bar.filled.below { fill: #2f9e6b; stroke: #2f9e6b; }
.level-bar.filled.above { fill: #d9622b; stroke: #d9622b; }
.level-bar.neutral { opacity: 1; }
.icon-btn[data-icon="piece"] { padding: .45rem; }
.icon-btn[data-icon="theme"] { padding: .7rem; }
.piece-glyph { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: min(1.5rem, calc(var(--icon-btn-size) * .4)); line-height: 1; user-select: none; }
.icon-btn[data-icon="piece"] .piece-glyph { background-size: contain; background-repeat: no-repeat; background-position: center; filter: var(--piece-filter); }
.icon-btn[data-piece="rook"] .piece-glyph { background-image: var(--piece-preview-image, var(--active-rook)); }
.icon-btn[data-piece="bishop"] .piece-glyph { background-image: var(--piece-preview-image, var(--active-bishop)); }
.icon-btn[data-piece="queen"] .piece-glyph { background-image: var(--piece-preview-image, var(--active-queen)); }
.icon-btn[data-piece="knight"] .piece-glyph { background-image: var(--piece-preview-image, var(--active-knight)); }
.icon-btn[data-piece="king"] .piece-glyph { background-image: var(--piece-preview-image, var(--active-king)); }
.icon-btn[data-piece="black-king"] .piece-glyph { background-image: var(--black-king); }
.icon-btn[data-color="w"], .icon-btn[data-color="w"]:hover { background: var(--icon-btn-bg-white); border-color: var(--icon-btn-border-white); }
.icon-btn[data-color="w"] svg { stroke: #202020; }
.icon-btn[data-color="b"], .icon-btn[data-color="b"]:hover { background: var(--icon-btn-bg-black); border-color: var(--icon-btn-border-black); }
.icon-btn[data-color="b"] svg { stroke: #fff; }
.rating-badge { font-size: 1.05rem; font-weight: 700; color: var(--icon-fg); font-variant-numeric: tabular-nums; }
.icon-btn[data-favorite="none"] svg { opacity: .4; fill: none; }
.icon-btn[data-favorite="favorite"] svg { stroke: var(--icon-fg); fill: none; }
.icon-btn[data-favorite="featured"] { background: var(--icon-btn-bg-featured); border-color: var(--favorite-accent); }
.icon-btn[data-favorite="featured"]:hover:not(:disabled) { background: var(--icon-btn-bg-hover); }
.icon-btn[data-favorite="featured"] svg { stroke: var(--icon-fg); fill: none; }


@media (max-width: 600px) {
  chess-toolbar .control-group { flex-direction: row; }
  chess-toolbar > chess-spacer { width: .55rem; height: var(--icon-btn-size); }
  chess-toolbar {
    position: static;
    right: auto;
    top: auto;
    transform: none;
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    margin-top: 0;
    gap: .65rem;
  }
}
@media (max-width: 1024px) {
  .pgn-player chess-toolbar.pgn-tools .control-group { flex-direction: row; }
  .pgn-player chess-toolbar.pgn-tools > chess-spacer { width: .55rem; height: var(--icon-btn-size); }
  .pgn-player chess-toolbar.pgn-tools { position: static; right: auto; top: auto; transform: none; flex-direction: row; flex-wrap: wrap; justify-content: center; width: 100%; margin: 0 0 1rem; }
}
.icon-btn[data-icon="group"][aria-pressed="false"] svg { opacity: .4; }

/* Countdown progress stays inside the control, leaving the toolbar spacing intact. */
chess-timer .icon-btn { position: relative; }
chess-timer .rating-badge { position: relative; font-size: .9rem; }
chess-timer .timer-ring { position: absolute; inset: 3px; pointer-events: none; }
chess-timer .timer-ring svg { width: 100%; height: 100%; stroke-width: 3; transform: rotate(-90deg) scaleY(-1); }
chess-timer .timer-track { stroke: var(--icon-fg); opacity: .2; }
chess-timer .timer-progress { stroke: var(--icon-fg); stroke-linecap: round; }
chess-timer .icon-btn[data-urgent="true"] .timer-progress { stroke: #ff493d; }

/* Optional action hierarchy; the default game controls retain their appearance. */
chess-button .icon-btn[data-variant="primary"],
chess-button .icon-btn[data-variant="secondary"],
chess-button .icon-btn[data-variant="quiet"] {
  --icon-btn-bg: var(--accent);
  --icon-btn-bg-hover: var(--accent-dark);
  --icon-fg: #fffaf0;
  background: var(--icon-btn-bg); color: var(--icon-fg);
  box-shadow: none;
}
chess-button .icon-btn[data-variant="secondary"] {
  --icon-btn-bg: #eef3ec; --icon-btn-bg-hover: #e1eade; --icon-fg: var(--accent-dark);
  border-color: #b6c7b9;
}
/* Quiet controls stay neutral grey; only the hover background hints at the button. */
chess-button .icon-btn[data-variant="quiet"] {
  --icon-btn-bg: transparent; --icon-btn-bg-hover: rgba(100, 116, 139, .12); --icon-fg: #64748b;
  border-color: transparent;
}
chess-button .icon-btn[data-variant]:not([data-variant=""]) svg { stroke-width: 1.8; }
/* Ant Design style variants. Accent comes from --button-accent so pages can theme them. */
chess-button .icon-btn:is([data-variant="outlined"], [data-variant="dashed"], [data-variant="solid"], [data-variant="filled"], [data-variant="text"], [data-variant="link"]) {
  --v-accent: var(--button-accent, var(--accent-dark));
  --icon-fg: var(--v-accent);
  --icon-btn-bg: transparent;
  --icon-btn-bg-hover: color-mix(in srgb, var(--v-accent) 10%, transparent);
  color: var(--icon-fg); box-shadow: none; border: 1px solid transparent; background: var(--icon-btn-bg);
}
chess-button .icon-btn[data-variant="outlined"] { border-color: var(--v-accent); }
chess-button .icon-btn[data-variant="dashed"] { border-style: dashed; border-color: var(--v-accent); }
chess-button .icon-btn[data-variant="solid"] { --icon-fg: #fffaf0; --icon-btn-bg: var(--v-accent); --icon-btn-bg-hover: color-mix(in srgb, var(--v-accent) 85%, #000); border-color: var(--v-accent); }
chess-button .icon-btn[data-variant="filled"] { --icon-btn-bg: color-mix(in srgb, var(--v-accent) 12%, transparent); --icon-btn-bg-hover: color-mix(in srgb, var(--v-accent) 20%, transparent); }
chess-button .icon-btn[data-variant="link"] { --icon-btn-bg-hover: transparent; padding-inline: .25rem; text-underline-offset: 3px; }
chess-button .icon-btn[data-variant="link"] .action-label { text-decoration: underline; text-decoration-color: transparent; }
chess-button .icon-btn[data-variant="link"]:hover .action-label { text-decoration-color: currentColor; }

chess-button .icon-btn[data-variant]:not([data-variant=""]):not(:disabled):hover { background: var(--icon-btn-bg-hover); }
chess-button[show-label] .icon-btn,
chess-button[content="label"] .icon-btn {
  width: auto; max-width: 100%; height: auto; min-height: var(--icon-btn-size);
  gap: .5rem; padding: .6rem .85rem; border-radius: 10px;
  color: var(--icon-fg); font: 600 14px/1.4 system-ui, sans-serif;
}
chess-button[show-label] .piece-glyph,
chess-button[content="label"] .piece-glyph { width: var(--icon-svg-size); height: var(--icon-svg-size); flex-shrink: 0; }
chess-button[show-label] .action-label,
chess-button[content="label"] .action-label { min-width: 0; overflow-wrap: anywhere; }
chess-button[show-label] .icon-btn:focus-visible,
chess-button[content="label"] .icon-btn:focus-visible,
chess-button[variant] .icon-btn:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }

chess-button .icon-btn[data-variant]:not([data-variant=""])[data-icon="hint"] svg { fill: none; stroke: var(--icon-fg); }

chess-button[size="small"][show-label] .icon-btn,
chess-button[size="small"][content="label"] .icon-btn { padding: .4rem .65rem; font-size: 13px; }
chess-button[size="large"][show-label] .icon-btn,
chess-button[size="large"][content="label"] .icon-btn { padding: .8rem 1.15rem; font-size: 16px; }
chess-button[size="medium"][show-label] .icon-btn,
chess-button[size="medium"][content="label"] .icon-btn { padding: .6rem .85rem; font-size: 14px; min-height: var(--icon-btn-size); }

/* Shapes: default (rounded rectangle), circle, round (pill). Without a shape attribute the legacy game-control look stays. */
chess-button[shape="default"] .icon-btn { border-radius: 10px; }
chess-button[shape="round"] .icon-btn { border-radius: 999px; }
chess-button[shape="circle"] { width: var(--icon-btn-size); height: var(--icon-btn-size); flex: 0 0 auto; }
chess-button[shape="circle"] .icon-btn { width: 100%; height: 100%; min-height: 0; padding: 0; border-radius: 50%; }
chess-button[shape="circle"] .action-label { display: none; } /* circle is icon-only; the label stays in aria-label/title */

/* Color (Ant Design API): default | primary | danger | preset names. Feeds --button-accent, which the variants read.
   The piece-side values w / b of the same attribute are untouched. */
/* The default color follows the active theme: pages or themes may set --button-default-color (falls back to the theme ink). */
chess-button[color="default"] { --button-accent: var(--button-default-color, var(--ink, #475569)); }
chess-button[color="primary"] { --button-accent: var(--accent-dark); }
chess-button[color="danger"] { --button-accent: #c0392b; }
chess-button[color="blue"] { --button-accent: #1677ff; }
chess-button[color="purple"] { --button-accent: #722ed1; }
chess-button[color="cyan"] { --button-accent: #13c2c2; }
chess-button[color="green"] { --button-accent: #389e0d; }
chess-button[color="magenta"] { --button-accent: #c41d7f; }
chess-button[color="pink"] { --button-accent: #eb2f96; }
chess-button[color="red"] { --button-accent: #f5222d; }
chess-button[color="orange"] { --button-accent: #d46b08; }
chess-button[color="yellow"] { --button-accent: #d4b106; }
chess-button[color="volcano"] { --button-accent: #fa541c; }
chess-button[color="geekblue"] { --button-accent: #2f54eb; }
chess-button[color="lime"] { --button-accent: #7cb305; }
chess-button[color="gold"] { --button-accent: #d48806; }

/* Icon placement (Ant Design API): start (default) | end. */
chess-button[icon-placement="end"] .icon-btn { flex-direction: row-reverse; }

/* block (Ant Design API): fit the parent width. */
chess-button[block] { display: flex; width: 100%; }
chess-button[block] .icon-btn { width: 100%; }

/* Reserve real layout space for touch targets, including typed/labelled buttons.
   The minimum must survive consumers' compact button rules. Margins reserve
   8px between neighbouring hosts without extending invisible hit areas. */
@media (pointer: coarse) {
  chess-button:is([size], :not([size])) {
    min-width: 44px;
    flex-shrink: 0;
    min-height: 44px;
    max-width: calc(100% - 8px);
    margin: 8px 4px;
  }
  /* A control group already spaces its buttons with `gap`; the margin would double it. */
  .control-group chess-button:is([size], :not([size])) { margin-block: 0; }
  chess-button:is([size], :not([size])) > button.icon-btn {
    margin: 0;
    min-width: 44px;
    min-height: 44px;
  }
}

/* Where the bar becomes a row it is one line: the appearance group first, the other groups after it on the left, the close button pinned to the right. A bar that does not fit scrolls sideways under the fixed close button. */
@media (max-width: 600px), (max-height: 500px) and (orientation: landscape) {
  chess-toolbar:not(.board-turn-controls) { position: sticky; top: 0; flex-direction: row; flex-wrap: nowrap; justify-content: flex-start; align-items: center; overflow: auto hidden; width: 100%; gap: .5rem; padding: calc(env(safe-area-inset-top, 0px) + 4px) 4px 4px; border-left: 0; background: transparent; }
  chess-toolbar:not(.board-turn-controls)::before, chess-toolbar:not(.board-turn-controls)::after { display: none; }
  chess-toolbar:not(.board-turn-controls) > * { order: 1; flex: none; }
  chess-toolbar:not(.board-turn-controls) > chess-spacer { width: .55rem; height: var(--icon-btn-size); }
  chess-toolbar:not(.board-turn-controls) .control-group { flex-direction: row; }
  chess-toolbar:not(.board-turn-controls) > .control-group[data-zone="bottom"] { order: 0; }
  chess-toolbar:not(.board-turn-controls) > chess-button.page-close { order: 2; margin-left: auto; top: auto; right: 0; }
  body:has(chess-toolbar:not(.board-turn-controls) > chess-button.page-close) { justify-content: flex-start; padding-top: 0; }
}
@media (max-width: 1024px) {
  body.pgn-player, body.position-editor { padding-top: 0; justify-content: flex-start; }
  .pgn-player .pgn-shell { margin-block: 0 auto; }
  .pgn-player chess-toolbar.pgn-tools, .position-editor #game-controls { position: sticky; top: 0; flex-direction: row; flex-wrap: nowrap; justify-content: flex-start; align-items: center; overflow: auto hidden; gap: .5rem; padding: calc(env(safe-area-inset-top, 0px) + 4px) 4px 4px; border-left: 0; background: transparent; }
  .pgn-player chess-toolbar.pgn-tools::before, .position-editor #game-controls::before, .pgn-player chess-toolbar.pgn-tools::after, .position-editor #game-controls::after { display: none; }
  .pgn-player chess-toolbar.pgn-tools > *, .position-editor #game-controls > * { order: 1; flex: none; }
  .pgn-player chess-toolbar.pgn-tools > .control-group[data-zone="bottom"], .position-editor #game-controls > .control-group[data-zone="bottom"] { order: 0; }
  .pgn-player chess-toolbar.pgn-tools > chess-button.page-close, .position-editor #game-controls > chess-button.page-close { order: 2; margin-left: auto; top: auto; right: 0; }
}

/* A short (zoomed) viewport cannot spare a pinned bar: it scrolls away with the page. */
@media (max-height: 500px) {
  .position-editor #game-controls { position: static; }
}

/* On phones the bar touches the top and side edges whatever the page's own padding. */
@media (max-width: 600px) {
  chess-toolbar:not(.board-turn-controls), .pgn-player chess-toolbar.pgn-tools, .position-editor #game-controls { width: calc(100% + .8rem); flex-basis: calc(100% + .8rem); margin: 0 -.4rem; box-sizing: border-box; }
}

/* The rail is out of flow: pages with one keep their content clear of it. */
:root { --action-bar-reserve: calc(5rem + env(safe-area-inset-right, 0px)); }
@media (min-width: 1025px) and (min-height: 501px) {
  body:has(chess-toolbar:not(.board-turn-controls) > chess-button.page-close) { padding-right: calc(1rem + var(--action-bar-reserve)); }
}
@media (min-width: 601px) and (max-width: 1024px) and (min-height: 501px) {
  body:has(chess-toolbar:not(.board-turn-controls) > chess-button.page-close):not(.position-editor):not(.pgn-player) { padding-right: calc(1rem + var(--action-bar-reserve)); }
}

/* One discoverable entry beside appearance controls on touch-capable devices. */
chess-button.board-mark-toggle { display: none; }
@media (any-pointer: coarse), (hover: none) {
  chess-button.board-mark-toggle { display: inline-flex; }
}
chess-button.board-mark-toggle[pressed="true"] { display: inline-flex; }
@media print { chess-button.board-mark-toggle { display: none; } }

/* Reusable color-preview icon; colors come from the chess-button color contract. */
.icon-btn[data-icon="color-swatch"] .color-swatch { fill: var(--icon-fg); }

/* Kullanıcı varsayılanı değiştirmediğinde düğme sönük görünür; tıklanabilir kalır. */
.icon-btn[data-idle]:not(:hover):not(:focus-visible) { opacity: .55; }
