/*
   Калькулятор руки — стили расчёта силы руки.
   Вынесено из css/modals.css. Тёмные стили остаются в css/dark-theme.css.
*/

.modal-content--window.modal-content--hand-calculator.is-maximized {
  height: auto !important;
  max-height: none !important;
}

.modal-actions--hand-calculator {
  justify-content: right;
  padding-right: 10px;
}

.modal-actions--hand-calculator #applyHandScoreButton {
  max-width: none;
  min-width: 220px;
}

.modal-actions--hand-calculator #closeHandCalculatorButton {
  flex: 0 0 auto;
}

.hand-calculator-result-controls .number-input-wrapper--compact {
  width: 112px;
}

.hand-calculator-result-controls .number-input-wrapper--compact input[type="number"] {
  width: 100%;
  min-height: 38px;
  margin: 0;
  padding: 7px 48px 7px 12px;
  font-size: 14px;
}

/* ── 9. Калькулятор — каркас ── */

.modal-content--hand-calculator {
  width: min(96vw, 1280px);
  max-width: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  box-sizing: border-box;
}

.modal-content--hand-calculator > .modal-title {
  text-align: center;
  flex-shrink: 0;
}

.modal-content--hand-calculator > .modal-window-header .modal-title {
  text-align: left;
}

.modal-content--hand-calculator > .modal-actions {
  flex-shrink: 0;
}

.hand-calculator-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  padding: 6px 8px 8px 4px;
}

.hand-calculator-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.hand-calculator-section.hand-calculator-player {
  flex-shrink: 0;
}

.hand-calculator-section.hand-calculator-tiles {
  /* Stable size — not tied to picker fit, to avoid wrap ↔ resize flicker. */
  --hand-selected-tile-h: clamp(38px, 4.5vw, 70px);
  --hand-selected-tile-w: calc(var(--hand-selected-tile-h) * 7 / 8);
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.hand-calculator-tiles .hand-section-heading {
  flex-shrink: 0;
}

.hand-calculator-tiles .hand-selected-tiles {
  flex-shrink: 0;
}

.hand-calculator-tiles .hand-tile-picker {
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hand-calculator-section.hand-calculator-structure,
.hand-calculator-conditions {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.hand-calculator-section.hand-calculator-structure {
  flex-shrink: 0;
}

.hand-calculator-conditions {
  flex: 0 1 auto;
  max-height: min(26vh, 220px);
}

.hand-calculator-structure h3,
.hand-calculator-conditions h3 {
  flex-shrink: 0;
}

.hand-calculator-panel-scroll,
.hand-calculator-structure-scroll,
.hand-calculator-conditions-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  padding-bottom: 6px;
  scroll-padding-bottom: 6px;
}

.hand-calculator-structure {
  flex: 0 1 auto;
  max-height: min(22vh, 200px);
}

.hand-calculator-result {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-height: min(20vh, 180px);
  max-height: min(24vh, 220px);
  overflow: hidden;
}

.hand-calculator-section {
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-surface-alt);
}

.hand-calculator-section h3 {
  margin: 0 0 6px;
  color: var(--color-heading);
  font-size: 14px;
}

.hand-calculator-player {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr);
  gap: 8px 12px;
  align-items: center;
}

.hand-player-name {
  color: var(--color-teal-accent);
  font-size: 18px;
  font-weight: 700;
}

.hand-calculator-player label,
.hand-field-label {
  color: var(--color-heading);
  font-size: 13px;
  font-weight: 700;
}

.hand-calculator-player select,
#handDecompositionSelect {
  width: 100%;
}

.hand-calculator-player p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--color-text-muted);
  font-size: 12px;
}

.hand-calculation-details-scroll {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  padding-bottom: 12px;
  scroll-padding-bottom: 12px;
}

.hand-calculation-details-body {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.hand-calculation-details-body--filled {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px 18px;
  align-items: start;
}

@media (min-width: 680px) and (max-width: 960px) {
  .hand-calculation-details-body--filled {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hand-calculation-details-body--filled .hand-result-meta,
  .hand-calculation-details-body--filled .hand-result-limited,
  .hand-calculation-details-body--filled .hand-result-details-columns {
    grid-column: 1 / -1;
  }

  .hand-result-details-columns:not(.hand-result-details-columns--limited) {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(180px, 0.85fr);
  }

  .hand-result-details-columns--limited {
    grid-template-columns: minmax(0, 1.4fr) minmax(180px, 0.8fr);
  }
}

@media (min-width: 900px) and (max-width: 960px) {
  .hand-result-details-columns:not(.hand-result-details-columns--limited) {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(200px, 0.8fr);
  }
}

/* ── 10. Калькулятор — выбранные плитки ── */

.hand-selected-tiles {
  --hand-selected-row-gap: 6px;
  --hand-selected-padding-block: 12px;
  --hand-selected-group-label-h: 18px;
  --hand-selected-group-inner-gap: 3px;
  --hand-selected-group-padding-block: 8px;
  --hand-selected-group-row-h: calc(
    var(--hand-selected-group-label-h) +
    var(--hand-selected-group-inner-gap) +
    var(--hand-selected-tile-h) +
    var(--hand-selected-group-padding-block)
  );
  display: flex;
  align-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--hand-selected-row-gap);
  /* Reserve 2 rows so wrapping does not steal height from the picker. */
  min-height: calc(2 * var(--hand-selected-group-row-h) + var(--hand-selected-row-gap) + var(--hand-selected-padding-block));
  max-height: min(220px, calc(3 * var(--hand-selected-group-row-h) + 2 * var(--hand-selected-row-gap) + var(--hand-selected-padding-block) + 2px));
  margin: 8px 0;
  padding: 6px 5px;
  border: 1px dashed var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hand-selected-tiles--grouped {
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: stretch;
  max-height: min(260px, calc(3 * var(--hand-selected-group-row-h) + 2 * var(--hand-selected-row-gap) + var(--hand-selected-padding-block) + 2px));
}

/* Ungrouped layout (single tiles before the hand is recognized):
   place tiles on the center of the table instead of the left edge. */
.hand-selected-tiles:not(.hand-selected-tiles--grouped) {
  justify-content: center;
}

.hand-selected-tiles--grouped .hand-selected-groups {
  margin-top: auto;
  margin-bottom: auto;
}

.hand-selected-groups {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--hand-selected-row-gap);
  width: 100%;
  min-width: 0;
}

.hand-selected-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 4px 5px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--color-panel);
}

.hand-selected-group__label {
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
  text-transform: uppercase;
}

.hand-selected-group__header-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  min-width: 0;
}

.hand-selected-group__header-row .hand-selected-group__label {
  min-width: 0;
}

.hand-selected-group__state {
  flex-shrink: 0;
  padding: 1px 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.35;
  text-transform: lowercase;
  pointer-events: none;
  user-select: none;
}

.hand-selected-group__state--closed {
  color: #0f627d;
}

.hand-selected-group__state--open {
  color: #2e7d32;
}

.hand-selected-group--closed.hand-selected-group--triple,
.hand-selected-group--closed.hand-selected-group--quad {
  box-shadow: inset 0 0 0 1px rgb(19 120 160 / 10%);
}

.hand-selected-group--toggle-open {
  cursor: pointer;
  transition:
    filter 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.hand-selected-group--toggle-open:hover {
  filter: brightness(0.97);
}

.hand-selected-group--toggle-open:active {
  filter: brightness(0.94);
}

.hand-selected-group--toggle-open .hand-selected-tile {
  cursor: default;
}

.hand-selected-group--toggle-open .hand-selected-tile--toggle-open,
.hand-selected-group--toggle-open .hand-selected-tile--toggle-open:hover {
  cursor: pointer;
}

.hand-selected-group--toggle-open .hand-selected-tile:not(.hand-selected-tile--toggle-open):hover {
  cursor: pointer;
}

.hand-selected-tile--toggle-open:not(.hand-selected-tile--concealed):hover {
  transform: none;
}

.hand-selected-tile--toggle-open:not(.hand-selected-tile--concealed):hover .hand-selected-tile__face--front {
  box-shadow: none;
}

.hand-selected-tile--flip {
  --r: 8px;
  --cap: 8px;
  --cap-d: 4px;
  /* perspective: 900px;
  perspective-origin: 50% 50%; */
  padding: 0;
  overflow: visible;
  transform: translateZ(0);
  background: transparent !important;
  box-shadow: none !important;
}

.hand-selected-tile--flip:not(.hand-selected-tile--concealed) {
  box-shadow:
    0 2px 0 rgb(150 116 38 / 24%),
    0 3px 0 rgb(120 90 20 / 12%),
    0 6px 14px rgb(120 90 20 / 16%) !important;
}

.hand-selected-tile--flip.hand-selected-tile--concealed {
  box-shadow:
    0 2px 0 rgb(0 0 0 / 24%),
    0 3px 0 rgb(0 0 0 / 12%),
    0 5px 10px rgb(0 0 0 / 16%) !important;
}

.hand-selected-tile--flip:not(.hand-selected-tile--concealed) {
  border: none;
  border-radius: 8px;
}

.hand-selected-tile--flip:not(.hand-selected-tile--concealed)::before {
  display: none;
}

.hand-selected-tile--flip.hand-selected-tile--concealed {
  border: none;
  border-radius: 8px;
}

.hand-selected-tile--flip.hand-selected-tile--concealed::before {
  display: none;
}

.hand-selected-tile--flip:hover,
.hand-selected-tile--flip.hand-selected-tile--concealed:hover {
  transform: none;
}

.hand-selected-tile--flip:not(.hand-selected-tile--concealed):hover {
  border-color: transparent;
  box-shadow:
    0 3px 0 rgb(150 116 38 / 22%),
    0 4px 0 rgb(120 90 20 / 10%),
    0 7px 16px rgb(120 90 20 / 18%) !important;
}

.hand-selected-tile--flip.hand-selected-tile--concealed:hover {
  border-color: transparent;
  box-shadow:
    0 2px 0 rgb(0 0 0 / 26%),
    0 3px 0 rgb(0 0 0 / 10%),
    0 6px 12px rgb(0 0 0 / 22%) !important;
}

.hand-selected-tile--flip.hand-selected-tile--toggle-open:not(.hand-selected-tile--concealed):hover .hand-selected-tile__face--front::before {
  border-color: color-mix(in srgb, var(--color-teal-accent) 72%, transparent);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 40%);
}

.hand-selected-tile--flip.hand-selected-tile--toggle-open:not(.hand-selected-tile--concealed):hover::after {
  content: '';
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 4px;
  width: 10px;
  height: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-teal-accent) 38%, transparent);
  opacity: 0.6;
  transform: translateX(-50%);
  pointer-events: none;
}

.hand-selected-tile--flip .hand-selected-tile__flipper {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform: rotateY(0deg);
  transition: transform 0.54s cubic-bezier(0.4, 0, 0.2, 1);
}

.hand-selected-tile--flip.hand-selected-tile--concealed .hand-selected-tile__flipper {
  transform: rotateY(180deg);
}

.hand-selected-tile__face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 2px;
  border-radius: 4px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.hand-selected-tile__face--front {
  transform: translateZ(11px);
  border: 1px solid #d4bc78;
  border-bottom-width: 3px;
  border-bottom-color: #a8873a;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 55%) 0%, rgb(255 255 255 / 12%) 32%, transparent 60%),
    linear-gradient(90deg, rgb(255 255 255 / 40%) 0%, transparent 12%, transparent 88%, rgb(120 90 20 / 12%) 100%),
    linear-gradient(180deg, #f3e9ce 0%, #ead9ad 52%, #e0cc98 100%);
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 85%),
    inset 1px 0 0 rgb(255 255 255 / 35%),
    inset -1px 0 0 rgb(120 90 20 / 10%),
    inset 0 -3px 4px rgb(120 90 20 / 16%);
}

.hand-selected-tile__face--front::after {
  display: none;
}

.hand-selected-tile__face--front::before {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid rgb(181 160 105 / 85%);
  border-radius: 5px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 35%);
  pointer-events: none;
}

.hand-selected-tile__face--back {
  transform: rotateY(180deg) translateZ(11px);
  border: 1px solid #1e684e;
  border-bottom-width: 3px;
  border-bottom-color: #123d30;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 14%) 0%, transparent 26%),
    linear-gradient(90deg, rgb(255 255 255 / 10%) 0%, transparent 14%, transparent 86%, rgb(0 0 0 / 16%) 100%),
    linear-gradient(165deg, #25644f 0%, #1a4d3c 55%, #153a2d 100%);
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 10%),
    inset 1px 0 0 rgb(255 255 255 / 8%),
    inset -1px 0 0 rgb(0 0 0 / 12%),
    inset 0 -3px 4px rgb(0 0 0 / 18%);
}

.hand-selected-tile__face--back::after {
  display: none;
}

.hand-selected-tile__face--back::before {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid rgb(206 240 226 / 55%);
  border-radius: 5px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 22%);
  pointer-events: none;
}

.hand-selected-tile--flip:not(.hand-selected-tile--concealed):hover .hand-selected-tile__face--front {
  background:
    linear-gradient(180deg, rgb(255 255 255 / 65%) 0%, rgb(255 255 255 / 16%) 32%, transparent 60%),
    linear-gradient(90deg, rgb(255 255 255 / 45%) 0%, transparent 12%, transparent 88%, rgb(120 90 20 / 10%) 100%),
    linear-gradient(180deg, #f8efd8 0%, #f1e2b9 52%, #e6d2a6 100%);
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 85%),
    inset 1px 0 0 rgb(255 255 255 / 35%),
    inset -1px 0 0 rgb(120 90 20 / 10%),
    inset 0 -3px 4px rgb(120 90 20 / 16%);
}

.hand-selected-tile--flip.hand-selected-tile--concealed:hover .hand-selected-tile__face--back {
  background:
    linear-gradient(180deg, rgb(255 255 255 / 18%) 0%, transparent 26%),
    linear-gradient(90deg, rgb(255 255 255 / 12%) 0%, transparent 14%, transparent 86%, rgb(0 0 0 / 14%) 100%),
    linear-gradient(165deg, #2a7059 0%, #1c543f 55%, #164030 100%);
}

/* Солидная кость: 6 граней (front/back/top/bottom/left/right), толщина 22px.
   Грани top/bottom/left/right видны во время переворота с наклоном rotateX. */
.hand-selected-tile__face--top {
  top: 50%;
  left: 0;
  width: 100%;
  height: 22px;
  margin-top: -11px;
  transform: rotateX(90deg) translateZ(calc(var(--hand-selected-tile-h) / 2));
  border-radius: 3px;
}

.hand-selected-tile__face--bottom {
  top: 50%;
  left: 0;
  width: 100%;
  height: 22px;
  margin-top: -11px;
  transform: rotateX(-90deg) translateZ(calc(var(--hand-selected-tile-h) / 2));
  border-radius: 3px;
}

.hand-selected-tile__face--right {
  top: 0;
  left: 50%;
  width: 22px;
  height: 100%;
  margin-left: -11px;
  transform: rotateY(90deg) translateZ(calc(var(--hand-selected-tile-w) / 2));
  border-radius: 3px;
}

.hand-selected-tile__face--left {
  top: 50%;
  left: 50%;
  width: 22px;
  height: 100%;
  margin-left: -11px;
  transform: translateY(-50%) rotateY(-90deg) translateZ(calc(var(--hand-selected-tile-w) / 2));
  border-radius: 4px;
  border: 1px solid #a8873a;
  border-bottom-width: 3px;
  border-top: 3px solid #e4d5af;
  perspective: 900px;
  perspective-origin: 50% 50%;
}

.hand-selected-tile__face--top,
.hand-selected-tile__face--bottom,
.hand-selected-tile__face--right,
.hand-selected-tile__face--left {
  display: block;
  padding: 0;
}

.hand-selected-tile__face--top {
  background: linear-gradient(180deg, #fdf9ec 0%, #f6ecd0 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 85%), inset 1px 0 0 rgb(255 255 255 / 45%), inset -1px 0 0 rgb(120 90 20 / 8%);
}

.hand-selected-tile__face--bottom {
  background: linear-gradient(180deg, #857859 0%, #a8873a 100%);
  box-shadow: inset 0 -1px 0 rgb(120 90 20 / 18%);
}

.hand-selected-tile__face--right,
.hand-selected-tile__face--left {
  background: linear-gradient(180deg, #f8f0dc 0%, #ebd9aa 50%, #dcc691 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 65%), inset -1px 0 0 rgb(120 90 20 / 30%), inset 1px 0 0 rgb(255 255 255 / 30%);
}

.hand-selected-tile--flip .hand-tile-back,
.hand-selected-tile--flip .hand-tile-back__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.hand-selected-tile--flip .hand-tile-back__svg {
  padding: 1px;
  box-sizing: border-box;
}

.hand-selected-tile--flip .hand-tile-face,
.hand-selected-tile--flip .hand-tile-label {
  width: 100%;
  height: 100%;
}

.hand-selected-group__tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-width: 0;
}

.hand-selected-group--sequence {
  border-color: rgb(23 158 211 / 28%);
  background: color-mix(in srgb, #179ed3 10%, var(--color-panel));
}

.hand-selected-group--triple {
  border-color: rgb(76 175 80 / 28%);
  background: color-mix(in srgb, #4caf50 10%, var(--color-panel));
}

.hand-selected-group--quad {
  border-color: rgb(224 188 81 / 34%);
  background: color-mix(in srgb, #e0bc51 12%, var(--color-panel));
}

.hand-selected-group--pair {
  border-color: rgb(175 76 76 / 28%);
  background: color-mix(in srgb, #af4c4c 10%, var(--color-panel));
}

.hand-selected-group--bonus,
.hand-selected-group--extra {
  border-color: rgb(19 120 160 / 22%);
  background: color-mix(in srgb, var(--color-teal-accent) 8%, var(--color-panel));
}

/* ── 11. Калькулятор — структура и разложение ── */

.hand-calculator-structure .app-select:has(#handDecompositionSelect) {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.app-select--hand-decomposition .app-select__trigger {
  align-items: stretch;
  height: auto;
}

.app-select--hand-decomposition .app-select__value {
  display: block;
  width: 100%;
  align-self: stretch;
}

.app-select--hand-decomposition .app-select__value .hand-decomposition-tooltip-groups {
  flex-wrap: wrap;
  row-gap: 5px;
}

.app-select--hand-decomposition .app-select__value .hand-decomposition-tooltip-group,
.app-select--hand-decomposition .app-select__value .hand-group-tiles {
  width: auto;
  max-width: none;
  overflow: visible;
}

.app-select--hand-decomposition .app-select__value .hand-decomposition-tooltip-group {
  flex-shrink: 0;
}

.app-select__menu--hand-decomposition .hand-decomposition-tooltip-groups,
.app-select__menu--hand-decomposition .hand-decomposition-menu-groups {
  flex-wrap: nowrap;
}

.hand-decomposition-menu-groups {
  display: flex;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 0;
}

.hand-decomposition-menu-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex-shrink: 0;
}

.hand-decomposition-menu-group__type {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  line-height: 1.2;
}

.hand-decomposition-menu-group__tiles {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
}

.hand-decomposition-menu-groups .hand-decomposition-tooltip-divider {
  align-self: stretch;
  height: auto;
  min-height: 38px;
}

.app-select__menu--hand-decomposition {
  padding: 8px;
  width: max-content;
  max-width: min(980px, calc(100vw - 16px));
}

.app-select__menu--hand-decomposition .app-select__option {
  display: block;
  width: 100%;
  max-width: none;
  min-width: max-content;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 6px 12px;
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: visible;
  line-height: 1.4;
  text-align: left;
  box-sizing: border-box;
}

.app-select__menu--hand-decomposition .app-select__option:hover,
.app-select__menu--hand-decomposition .app-select__option:focus-visible {
  background: rgb(224 188 81 / 14%);
  color: var(--color-heading);
}

.app-select__menu--hand-decomposition .app-select__option.is-selected {
  background: var(--color-gold-light);
  color: var(--color-heading);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--color-gold);
}

.hand-decomposition-tooltip-groups {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0;
}

.hand-decomposition-tooltip-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
}

.hand-decomposition-tooltip-divider {
  width: 1px;
  height: 28px;
  margin: 0 10px;
  background: color-mix(in srgb, var(--color-border) 90%, transparent);
  flex-shrink: 0;
}

/* ── 12. Калькулятор — шапка секции и счётчик ── */

.hand-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hand-section-heading h3 {
  margin-bottom: 0;
}

.hand-section-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#handTileCounter {
  color: var(--color-text-muted);
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 18px;
  white-space: nowrap;
}

.hand-clear-button {
  width: auto;
  min-width: 0;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 6px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.hand-clear-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hand-clear-button i {
  margin: 0;
  font-size: 11px;
}

.hand-clear-button__label {
  margin-left: 5px;
}

.hand-empty-state {
  width: 100%;
  color: var(--color-text-muted);
  font-size: 16px;
  text-align: center;
}

/* ── 13. Калькулятор — плитки и пикер ── */

.hand-selected-tile,
.hand-tile-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  min-width: 46px;
  max-width: 46px;
  height: 52px;
  max-height: 52px;
  margin: 0;
  padding: 3px;
  border: 1px solid #d4bc78;
  border-bottom-width: 3px;
  border-bottom-color: #a8873a;
  border-radius: 9px;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 55%) 0%, rgb(255 255 255 / 12%) 32%, transparent 60%),
    linear-gradient(90deg, rgb(255 255 255 / 40%) 0%, transparent 12%, transparent 88%, rgb(120 90 20 / 12%) 100%),
    linear-gradient(180deg, #f3e9ce 0%, #ead9ad 52%, #e0cc98 100%);
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 17px;
  line-height: 1;
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 85%),
    inset 1px 0 0 rgb(255 255 255 / 35%),
    inset -1px 0 0 rgb(120 90 20 / 10%),
    inset 0 -3px 4px rgb(120 90 20 / 16%),
    0 2px 0 rgb(150 116 38 / 24%),
    0 3px 0 rgb(120 90 20 / 12%),
    0 6px 14px rgb(120 90 20 / 16%);
  overflow: visible;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.hand-selected-tile::before,
.hand-tile-button::before {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid rgb(181 160 105 / 85%);
  border-radius: 6px;
  pointer-events: none;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 35%);
}

.hand-selected-tiles .hand-selected-tile {
  width: var(--hand-selected-tile-w);
  min-width: var(--hand-selected-tile-w);
  max-width: var(--hand-selected-tile-w);
  height: var(--hand-selected-tile-h);
  min-height: var(--hand-selected-tile-h);
  max-height: var(--hand-selected-tile-h);
  padding: 2px;
  border-radius: 4px;
  font-size: calc(var(--hand-selected-tile-h) * 0.32);
  line-height: 1;
}

.hand-selected-tiles .hand-selected-tile::before {
  border-radius: 5px;
}

.hand-selected-tiles .hand-selected-tile--flip {
  padding: 0;
}

.hand-selected-tile--concealed:not(.hand-selected-tile--flip),
.hand-selected-tile--concealed:not(.hand-selected-tile--flip)::before {
  border-color: #1e684e;
  border-bottom-color: #123d30;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 14%) 0%, transparent 26%),
    linear-gradient(90deg, rgb(255 255 255 / 10%) 0%, transparent 14%, transparent 86%, rgb(0 0 0 / 16%) 100%),
    linear-gradient(165deg, #25644f 0%, #1a4d3c 55%, #153a2d 100%);
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 10%),
    inset 1px 0 0 rgb(255 255 255 / 8%),
    inset -1px 0 0 rgb(0 0 0 / 12%),
    inset 0 -3px 4px rgb(0 0 0 / 18%),
    0 2px 0 rgb(0 0 0 / 24%),
    0 3px 0 rgb(0 0 0 / 12%),
    0 5px 10px rgb(0 0 0 / 16%);
}

.hand-selected-tile--concealed:not(.hand-selected-tile--flip)::before {
  inset: 2px;
  border-color: rgb(206 240 226 / 55%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 22%);
}

.hand-selected-tile--concealed:not(.hand-selected-tile--flip):hover {
  transform: none;
  border-color: #1e684e;
  border-bottom-color: #123d30;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 18%) 0%, transparent 26%),
    linear-gradient(90deg, rgb(255 255 255 / 12%) 0%, transparent 14%, transparent 86%, rgb(0 0 0 / 14%) 100%),
    linear-gradient(165deg, #2a7059 0%, #1c543f 55%, #164030 100%);
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 12%),
    inset 1px 0 0 rgb(255 255 255 / 9%),
    inset -1px 0 0 rgb(0 0 0 / 11%),
    inset 0 -3px 4px rgb(0 0 0 / 16%),
    0 2px 0 rgb(0 0 0 / 22%),
    0 3px 0 rgb(0 0 0 / 10%),
    0 6px 12px rgb(0 0 0 / 18%);
}

.hand-tile-back {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  overflow: hidden;
}

.hand-tile-back__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.hand-selected-tiles .hand-tile-label,
.hand-selected-tiles .hand-tile-face {
  width: 100%;
  height: 100%;
}

.hand-selected-tiles .hand-tile-face {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hand-selected-tiles .hand-tile-svg {
  display: block;
  width: auto;
  height: calc(var(--hand-selected-tile-h) * 0.94);
  max-width: calc(var(--hand-selected-tile-w) * 0.96);
  max-height: calc(var(--hand-selected-tile-h) * 0.94);
  aspect-ratio: 1;
  filter: brightness(0.80);
}

.hand-selected-tiles .hand-tile-face--bamboo .hand-tile-svg,
.hand-selected-tiles .hand-tile-face--bamboo-1 .hand-tile-svg,
.hand-selected-tiles .hand-tile-face--dots .hand-tile-svg {
  height: calc(var(--hand-selected-tile-h) * 0.98);
  max-width: calc(var(--hand-selected-tile-w) * 0.99);
  max-height: calc(var(--hand-selected-tile-h) * 0.98);
}

.hand-selected-tiles .hand-tile-face--season .hand-tile-svg {
  width: calc(var(--hand-selected-tile-w) * 0.96);
  height: calc(var(--hand-selected-tile-h) * 0.5);
  max-width: 96%;
  max-height: 52%;
  aspect-ratio: auto;
}

.hand-selected-tiles .hand-tile-label--symbols .hand-tile-number,
.hand-selected-tiles .hand-tile-label--wind .hand-tile-wind-kanji {
  font-size: calc(var(--hand-selected-tile-h) * 0.44);
  line-height: 1;
}

.hand-selected-tiles .hand-tile-label--symbols .hand-tile-suit,
.hand-selected-tiles .hand-tile-label--wind .hand-tile-wind-letter {
  font-size: calc(var(--hand-selected-tile-h) * 0.3);
  line-height: 1;
}

.hand-selected-tiles .hand-tile-label--dragon,
.hand-selected-tiles .hand-tile-label--dragon-green,
.hand-selected-tiles .hand-tile-label--dragon-white {
  font-size: calc(var(--hand-selected-tile-h) * 0.42);
  line-height: 1;
}

.hand-selected-tiles .hand-tile-season-label {
  font-size: calc(var(--hand-selected-tile-h) * 0.4);
}

.hand-selected-tiles .hand-tile-season-points {
  font-size: calc(var(--hand-selected-tile-h) * 0.2);
}

.hand-selected-tiles .hand-tile-number-badge {
  min-width: max(10px, calc(var(--hand-selected-tile-h) * 0.28));
  height: max(10px, calc(var(--hand-selected-tile-h) * 0.28));
  padding: 0 max(1px, calc(var(--hand-selected-tile-h) * 0.04));
  font-size: max(7px, calc(var(--hand-selected-tile-h) * 0.2));
}

.hand-selected-tiles .hand-selected-tile .hand-tile-count,
.hand-selected-tiles .hand-selected-tile small {
  right: 1px;
  top: 1px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-width: 1.5px;
  font-size: 9px;
  box-shadow: 0 1px 4px rgb(0 0 0 / 24%);
}

.hand-tile-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(180deg, rgb(255 255 255 / 24%) 0%, transparent 55%);
}

.hand-tile-label--symbols {
  flex-direction: column;
  gap: 1px;
  color: #b71c1c;
  font-weight: 700;
  text-shadow: 0 1px 0 rgb(255 255 255 / 65%), 0 0 8px rgb(183 28 28 / 12%);
}

.hand-tile-label--symbols .hand-tile-number {
  font-size: 16px;
  line-height: 1;
}

.hand-tile-label--symbols .hand-tile-suit {
  font-size: 11px;
  line-height: 1;
}

.hand-tile-label--wind {
  flex-direction: column;
  gap: 1px;
  color: #1e3a5f;
  font-weight: 700;
  text-shadow: 0 1px 0 rgb(255 255 255 / 60%);
}

.hand-tile-label--wind .hand-tile-wind-kanji {
  font-size: 16px;
  line-height: 1;
}

.hand-tile-label--wind .hand-tile-wind-letter {
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.hand-tile-label--dragon {
  color: #b71c1c;
  font-size: 17px;
  font-weight: 700;
  text-shadow: 0 1px 0 rgb(255 255 255 / 60%), 0 0 6px rgb(183 28 28 / 15%);
}

.hand-tile-label--dragon-green {
  color: #2e7d32;
  font-size: 17px;
  font-weight: 700;
  text-shadow: 0 1px 0 rgb(255 255 255 / 60%), 0 0 6px rgb(46 125 50 / 18%);
}

.hand-tile-label--dragon-white {
  color: #4b5563;
  font-size: 16px;
  font-weight: 700;
  border: 1.5px solid #8a939f;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  box-sizing: border-box;
  background: linear-gradient(180deg, #ffffff 0%, #eef1f4 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 90%), 0 1px 2px rgb(0 0 0 / 8%);
}

.hand-tile-face {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: transparent;
}

.hand-tile-number-badge {
  position: absolute;
  bottom: -2px;
  left: -1px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.45em;
  height: 1.45em;
  padding: 0 0.22em;
  border-radius: 999px;
  box-sizing: border-box;
  color: #f5edd8;
  background: rgb(28 22 14 / 90%);
  border: 1px solid rgb(224 188 81 / 42%);
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  box-shadow:
    0 0 0 1px rgb(255 255 255 / 10%),
    0 1px 3px rgb(0 0 0 / 38%);
  pointer-events: none;
}

.hand-tile-svg {
  display: block;
  /* width: 30px;
  height: 30px; */
}

.hand-tile-face--dots .hand-tile-svg {
  /* width: 32px;
  height: 32px; */
}

.hand-tile-face--bamboo-1 .hand-tile-svg {
  /* width: 34px;
  height: 34px; */
}

.hand-tile-face--season {
  flex-direction: column;
  gap: 0;
}

.hand-tile-face--season .hand-tile-svg {
  width: 100%;
  height: 18px;
}

.hand-tile-season-label {
  color: #5d4037;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.hand-tile-season-points {
  position: absolute;
  right: 2px;
  bottom: 2px;
  color: #2e7d32;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
}

.hand-tile-face--season-spring .hand-tile-season-label {
  color: #ad1457;
}

.hand-tile-face--season-summer .hand-tile-season-label {
  color: #ef6c00;
}

.hand-tile-face--season-autumn .hand-tile-season-label {
  color: #e65100;
}

.hand-tile-face--season-winter .hand-tile-season-label {
  color: #0277bd;
}

.hand-tile-face--season-plum .hand-tile-season-label {
  color: #c2185b;
}

.hand-tile-face--season-orchid .hand-tile-season-label {
  color: #7b1fa2;
}

.hand-tile-face--season-chrysanthemum .hand-tile-season-label {
  color: #ef6c00;
}

.hand-tile-face--season-flower-bamboo .hand-tile-season-label {
  color: #2e7d32;
}

.hand-group-tile-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 28px;
  flex-shrink: 0;
  vertical-align: middle;
  box-sizing: border-box;
  padding: 1px;
  border: 1px solid #d4bc78;
  border-bottom-width: 2px;
  border-bottom-color: #b8963a;
  border-radius: 5px;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 45%) 0%, transparent 35%),
    linear-gradient(180deg, #fffef9 0%, #f3e6c4 100%);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 75%),
    0 1px 3px rgb(120 90 20 / 16%);
}

.hand-group-tile-face .hand-tile-label {
  width: 100%;
  height: 100%;
}

.hand-group-tile-face .hand-tile-face {
  width: 100%;
  height: 100%;
}

.hand-group-tile-face .hand-tile-svg {
  width: 22px;
  height: 22px;
}

.hand-group-tile-face .hand-tile-number-badge {
  top: 0;
  left: 1px;
  min-width: 11px;
  height: 11px;
  padding: 0 1px;
  font-size: 8px;
}

.hand-group-tile-face .hand-tile-label--symbols .hand-tile-number {
  font-size: 11px;
}

.hand-group-tile-face .hand-tile-label--symbols .hand-tile-suit {
  font-size: 8px;
}

.hand-group-tile-face .hand-tile-label--wind,
.hand-group-tile-face .hand-tile-label--dragon,
.hand-group-tile-face .hand-tile-label--dragon-green {
  font-size: 13px;
}

.hand-group-tile-face .hand-tile-label--wind .hand-tile-wind-kanji {
  font-size: 11px;
}

.hand-group-tile-face .hand-tile-label--wind .hand-tile-wind-letter {
  font-size: 7px;
}

.hand-group-tile-face .hand-tile-season-label {
  font-size: 11px;
}

.hand-group-tile-face .hand-tile-season-points {
  right: 0;
  bottom: 0;
  font-size: 6px;
}

.hand-group-tile-face .hand-tile-face--season .hand-tile-svg {
  height: 12px;
}

.hand-group-tiles {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--color-heading);
  font-family: inherit;
  font-size: 14px;
}

.hand-group-tiles--sequence {
  border-color: rgb(23 158 211 / 22%);
  background: color-mix(in srgb, #179ed3 10%, var(--color-surface));
}

.hand-group-tiles--triple {
  border-color: rgb(76 175 80 / 22%);
  background: color-mix(in srgb, #4caf50 10%, var(--color-surface));
}

.hand-group-tiles--quad {
  border-color: rgb(224 188 81 / 28%);
  background: color-mix(in srgb, #e0bc51 12%, var(--color-surface));
}

.hand-group-tiles--pair {
  border-color: rgb(175 76 76 / 22%);
  background: color-mix(in srgb, #af4c4c 10%, var(--color-surface));
}

.hand-selected-tile:not(.hand-selected-tile--concealed):not(.hand-selected-tile--flip):hover,
.hand-tile-button:hover {
  background:
    linear-gradient(180deg, rgb(255 255 255 / 65%) 0%, rgb(255 255 255 / 16%) 32%, transparent 60%),
    linear-gradient(90deg, rgb(255 255 255 / 45%) 0%, transparent 12%, transparent 88%, rgb(120 90 20 / 10%) 100%),
    linear-gradient(180deg, #f8efd8 0%, #f1e2b9 52%, #e6d2a6 100%);
  border-color: #c4a044;
  transform: translateY(-2px);
  box-shadow:
    inset 0 2px 2px rgb(255 255 255 / 92%),
    inset 1px 0 0 rgb(255 255 255 / 40%),
    inset -1px 0 0 rgb(120 90 20 / 8%),
    inset 0 -3px 4px rgb(120 90 20 / 14%),
    0 3px 0 rgb(150 116 38 / 22%),
    0 4px 0 rgb(120 90 20 / 10%),
    0 7px 16px rgb(120 90 20 / 18%);
}

.hand-selected-tile:not(.hand-selected-tile--concealed):hover .hand-tile-face::after,
.hand-tile-button:hover .hand-tile-face::after {
  opacity: 0.42;
}

.hand-selected-tile:active,
.hand-tile-button:active {
  transform: translateY(0);
  box-shadow:
    inset 0 2px 3px rgb(120 90 20 / 18%),
    inset 1px 0 0 rgb(255 255 255 / 25%),
    inset -1px 0 0 rgb(120 90 20 / 14%),
    inset 0 -2px 3px rgb(120 90 20 / 10%),
    0 1px 0 rgb(150 116 38 / 20%),
    0 2px 4px rgb(120 90 20 / 14%);
}

.hand-selected-tile small,
.hand-tile-count {
  position: absolute;
  right: -9px;
  top: -9px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 2px solid #fffdf7;
  border-radius: 999px;
  background: #b71c1c;
  color: #fff;
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  box-sizing: border-box;
  box-shadow: 0 2px 6px rgb(0 0 0 / 28%);
  pointer-events: none;
}

.hand-tile-button .hand-tile-count {
  background: #115e59;
}

.hand-tile-count:empty {
  display: none;
}

/* ── Взятие кости: «перелёт» из пикера в руку ── */

.hand-tile--picked {
  z-index: 2;
  animation: handTilePickIn 0.26s ease-out;
}

.hand-tiles--settle {
  animation: handTilesSettle 0.28s ease-out;
}

@keyframes handTilePickIn {
  0% {
    transform: translateY(14px) scale(0.9);
    opacity: 0;
  }
  60% {
    transform: translateY(-2px) scale(1.02);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes handTilesSettle {
  0% {
    transform: scale(0.97);
    opacity: 0.6;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.hand-tile-picker {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  gap: 11px;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 4px 10px 4px 0px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  --hand-picker-tile-h: 46px;
  --hand-picker-tile-w: calc(var(--hand-picker-tile-h) * 7 / 8);
  --hand-picker-suit-tile-h: var(--hand-picker-tile-h);
  --hand-picker-suit-tile-w: var(--hand-picker-tile-w);
}

.hand-tile-picker .hand-tile-family {
  width: 100%;
  min-width: 0;
  padding: 6px 8px 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--color-panel);
  overflow: visible;
  box-sizing: border-box;
}

.hand-tile-picker .hand-tile-family h4 {
  margin: 0 0 6px;
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
  text-transform: uppercase;
}

.hand-tile-picker .hand-tile-family--symbols {
  border-color: rgb(183 28 28 / 22%);
  /* border-left-color: #b71c1c; */
  /* background: color-mix(in srgb, #b71c1c 7%, var(--color-panel)); */
}

.hand-tile-picker .hand-tile-family--bamboo {
  border-color: rgb(46 125 50 / 22%);
  /* border-left-color: #2e7d32; */
  /* background: color-mix(in srgb, #2e7d32 7%, var(--color-panel)); */
}

.hand-tile-picker .hand-tile-family--dots {
  border-color: rgb(21 101 192 / 22%);
  /* border-left-color: #1565c0; */
  /* background: color-mix(in srgb, #1565c0 7%, var(--color-panel)); */
}

.hand-tile-picker .hand-tile-family--honors {
  border-color: rgb(160 129 19 / 49%);
  /* border-left-color: #fa944a; */
  /* background: color-mix(in srgb, var(--color-teal-accent) 7%, var(--color-panel)); */
}

.hand-tile-picker .hand-tile-family--honors h4 {
  margin-bottom: 4px;
}

.hand-tile-picker .hand-tile-family {
  --hand-picker-tile-local-h: var(--hand-picker-tile-h);
  --hand-picker-tile-local-w: var(--hand-picker-tile-w);
}

.hand-tile-picker .hand-tile-family--symbols,
.hand-tile-picker .hand-tile-family--bamboo,
.hand-tile-picker .hand-tile-family--dots {
  --hand-picker-tile-local-h: var(--hand-picker-suit-tile-h, var(--hand-picker-tile-h));
  --hand-picker-tile-local-w: var(--hand-picker-suit-tile-w, var(--hand-picker-tile-w));
}

.hand-tile-picker.hand-tile-picker--fitted {
  gap: 7px;
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-family {
  padding: 4px 6px 5px;
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-family h4 {
  margin-bottom: 3px;
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-grid {
  gap: 4px;
}

.hand-tile-family {
  width: 100%;
  min-width: 0;
}

.hand-tile-family h4 {
  margin: 0 0 6px;
  color: var(--color-text-muted);
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.hand-tile-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 2px 2px 0;
  overflow: hidden;
  place-items: center;
}

.hand-tile-picker .hand-tile-grid {
  gap: 6px;
  padding: 2px 1px 0;
  overflow: visible;
}

.hand-tile-grid--honors {
  display: grid;
  grid-template-columns:
    repeat(4, minmax(0, 1fr))
    1px
    repeat(3, minmax(0, 1fr))
    1px
    repeat(4, minmax(0, 1fr));
  gap: 4px;
  align-items: center;
  overflow: visible;
}

.hand-tile-group-divider {
  width: 1px;
  height: 100%;
  min-height: 0;
  align-self: stretch;
  justify-self: center;
  margin: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-teal-accent) 28%, var(--color-border));
}

.hand-tile-picker .hand-tile-button {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  aspect-ratio: 7 / 8;
  justify-self: center;
  align-self: center;
  padding: 1px;
  font-size: var(--hand-picker-tile-local-h);
  line-height: 1;
  isolation: isolate;
}

.hand-tile-picker .hand-tile-label,
.hand-tile-picker .hand-tile-face {
  width: 100%;
  height: 100%;
}

.hand-tile-picker .hand-tile-face {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.hand-tile-picker .hand-tile-svg {
  display: block;
  width: auto;
  height: calc(var(--hand-picker-tile-local-h) * 0.94);
  max-width: calc(var(--hand-picker-tile-local-w) * 0.96);
  max-height: calc(var(--hand-picker-tile-local-h) * 0.94);
  aspect-ratio: 1;
  filter: brightness(0.80);
}

.hand-tile-picker .hand-tile-face--bamboo,
.hand-tile-picker .hand-tile-face--bamboo-1 {
  padding: 0;
}

.hand-tile-picker .hand-tile-face--bamboo .hand-tile-svg,
.hand-tile-picker .hand-tile-face--bamboo-1 .hand-tile-svg {
  height: calc(var(--hand-picker-tile-local-h) * 0.98);
  max-width: calc(var(--hand-picker-tile-local-w) * 0.99);
  max-height: calc(var(--hand-picker-tile-local-h) * 0.98);
}

.hand-tile-picker .hand-tile-face--dots {
  padding: 0;
}

.hand-tile-picker .hand-tile-face--dots .hand-tile-svg {
  height: calc(var(--hand-picker-tile-local-h) * 0.98);
  max-width: calc(var(--hand-picker-tile-local-w) * 0.99);
  max-height: calc(var(--hand-picker-tile-local-h) * 0.98);
}

.hand-tile-picker .hand-tile-face--season {
  gap: 0;
  padding: 0;
}

.hand-tile-picker .hand-tile-face--season .hand-tile-svg {
  width: calc(var(--hand-picker-tile-local-w) * 0.96);
  height: calc(var(--hand-picker-tile-local-h) * 0.5);
  max-width: 96%;
  max-height: 52%;
  aspect-ratio: auto;
}

.hand-tile-picker .hand-tile-label--symbols {
  gap: calc(var(--hand-picker-tile-local-h) * 0.02);
}

.hand-tile-picker .hand-tile-label--symbols .hand-tile-number {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.44);
  line-height: 1;
}

.hand-tile-picker .hand-tile-label--symbols .hand-tile-suit {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.3);
  line-height: 1;
}

.hand-tile-picker .hand-tile-label--wind {
  gap: calc(var(--hand-picker-tile-local-h) * 0.02);
}

.hand-tile-picker .hand-tile-label--wind .hand-tile-wind-kanji {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.4);
  line-height: 1;
}

.hand-tile-picker .hand-tile-label--wind .hand-tile-wind-letter {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.22);
  line-height: 1;
}

.hand-tile-picker .hand-tile-label--dragon,
.hand-tile-picker .hand-tile-label--dragon-green {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.42);
  line-height: 1;
}

.hand-tile-picker .hand-tile-label--dragon-white {
  width: calc(var(--hand-picker-tile-local-h) * 0.46);
  height: calc(var(--hand-picker-tile-local-h) * 0.46);
  font-size: calc(var(--hand-picker-tile-local-h) * 0.34);
}

.hand-tile-picker .hand-tile-season-label {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.28);
  line-height: 1;
}

.hand-tile-picker .hand-tile-season-points {
  font-size: calc(var(--hand-picker-tile-local-h) * 0.16);
  line-height: 1;
}

.hand-tile-picker .hand-tile-number-badge {
  min-width: max(12px, calc(var(--hand-picker-tile-local-h) * 0.25));
  height: max(12px, calc(var(--hand-picker-tile-local-h) * 0.25));
  padding: 0 0.14em;
  font-size: max(10px, calc(var(--hand-picker-tile-local-h) * 0.2));
  line-height: 1;
}

.hand-tile-picker .hand-tile-button:active {
  z-index: 1;
}

.hand-tile-picker .hand-tile-button .hand-tile-count {
  right: -4px;
  top: -4px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-width: 1.5px;
  font-size: 9px;
  box-shadow: 0 1px 4px rgb(0 0 0 / 24%);
}

.hand-tile-picker.hand-tile-picker--fitted {
  overflow-y: hidden;
}

.hand-tile-picker.hand-tile-picker--fitted.hand-tile-picker--fitted-overflow {
  overflow-y: auto;
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-grid:not(.hand-tile-grid--honors) {
  grid-template-columns: repeat(9, var(--hand-picker-tile-local-w));
  justify-content: center;
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-grid--honors {
  grid-template-columns:
    repeat(4, var(--hand-picker-tile-local-w))
    1px
    repeat(3, var(--hand-picker-tile-local-w))
    1px
    repeat(4, var(--hand-picker-tile-local-w));
  justify-content: center;
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-button {
  width: var(--hand-picker-tile-local-w);
  min-width: var(--hand-picker-tile-local-w);
  max-width: var(--hand-picker-tile-local-w);
  height: var(--hand-picker-tile-local-h);
  min-height: var(--hand-picker-tile-local-h);
  max-height: var(--hand-picker-tile-local-h);
  aspect-ratio: auto;
  padding: 1px;
  font-size: var(--hand-picker-tile-local-h);
}

.hand-tile-picker.hand-tile-picker--fitted .hand-tile-button .hand-tile-count {
  min-width: max(12px, calc(var(--hand-picker-tile-local-h) * 0.34));
  height: max(12px, calc(var(--hand-picker-tile-local-h) * 0.34));
  font-size: max(7px, calc(var(--hand-picker-tile-local-h) * 0.2));
}

.hand-tile-picker:not(.hand-tile-picker--fitted) .hand-tile-button {
  width: min(100%, calc(var(--hand-picker-tile-h) * 7 / 8));
  min-width: 0;
  max-width: calc(var(--hand-picker-tile-h) * 7 / 8);
  height: auto;
  max-height: var(--hand-picker-tile-h);
  aspect-ratio: 7 / 8;
}

.hand-tile-picker:not(.hand-tile-picker--fitted) .hand-tile-family--honors .hand-tile-button {
  width: min(100%, calc(var(--hand-picker-tile-h) * 7 / 8));
  min-width: 0;
  max-width: calc(var(--hand-picker-tile-h) * 7 / 8);
  height: auto;
  aspect-ratio: 7 / 8;
  padding: 1px;
  font-size: var(--hand-picker-tile-local-h);
  line-height: 1;
}

.hand-tile-picker .hand-tile-family--honors .hand-tile-face--season {
  gap: 0;
  padding-top: 0;
}

.hand-tile-picker .hand-tile-family--honors .hand-tile-face--season::after {
  display: none;
}

/* ── 14. Калькулятор — группы и условия ── */

.hand-structure-status {
  margin: 0 0 6px;
  padding: 6px 9px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--color-red) 12%, transparent);
  color: var(--color-text);
  font-size: 16px;
  overflow: visible;
}

.hand-structure-status--valid {
  background: color-mix(in srgb, var(--color-green) 14%, transparent);
}

.hand-field-label {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
}

.hand-group-tiles {
  grid-area: tiles;
  justify-self: start;
}

.hand-condition input[type="checkbox"],
    .hand-teaching-toggle input[type="checkbox"] {
appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin: 0;
  border: 2px solid color-mix(in srgb, var(--color-text-muted) 34%, var(--color-border));
  border-radius: 5px;
  background: var(--color-surface);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.hand-condition input[type="checkbox"]::after,
    .hand-teaching-toggle input[type="checkbox"]::after {
content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transform-origin: center;
  transition: transform 0.12s ease;
}

.hand-condition input[type="checkbox"]:checked,
    .hand-teaching-toggle input[type="checkbox"]:checked {
background: var(--color-green);
  border-color: var(--color-green);
}

.hand-condition input[type="checkbox"]:checked::after,
    .hand-teaching-toggle input[type="checkbox"]:checked::after {
transform: rotate(45deg) scale(1);
}

.hand-condition input[type="checkbox"]:focus-visible,
    .hand-teaching-toggle input[type="checkbox"]:focus-visible {
outline: 2px solid var(--color-teal-accent);
  outline-offset: 2px;
}

.hand-condition {
display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--color-text);
  cursor: pointer;
  font-size: 16px;
  line-height: 1.3;
}

.hand-condition-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}

.hand-condition {
  min-height: 30px;
  padding: 6px 9px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-panel);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.hand-condition span {
  flex: 1;
  min-width: 0;
  padding-top: 1px;
}

.hand-condition:hover {
  border-color: color-mix(in srgb, var(--color-teal-accent) 40%, var(--color-border));
  background: color-mix(in srgb, var(--color-teal-accent) 6%, var(--color-panel));
}

.hand-condition:has(input:checked) {
  border-color: color-mix(in srgb, var(--color-green) 45%, var(--color-border));
  background: color-mix(in srgb, var(--color-green) 10%, var(--color-panel));
}

.hand-condition--primary {
  font-weight: 700;
}

.hand-condition--primary:has(input:checked) {
  border-color: color-mix(in srgb, var(--color-green) 55%, var(--color-border));
  background: color-mix(in srgb, var(--color-green) 14%, var(--color-panel));
}

.hand-condition-grid--limited {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.hand-condition-subtitle {
  margin: 8px 0 5px;
  padding-top: 6px;
  border-top: 1px dashed var(--color-border);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.hand-condition--limited {
  background: color-mix(in srgb, var(--color-gold) 10%, var(--color-panel));
}

.hand-condition--limited:hover {
  background: color-mix(in srgb, var(--color-gold) 14%, var(--color-panel));
}

.hand-condition--limited:has(input:checked) {
  border-color: color-mix(in srgb, var(--color-gold) 55%, var(--color-border));
  background: color-mix(in srgb, var(--color-gold) 18%, var(--color-panel));
}

.hand-limit-field {
  display: block;
  margin: 0 0 6px;
  color: var(--color-text-muted);
  font-size: 16px;
  font-weight: 600;
}

#handScoreLimitInput {
  width: 100%;
  max-width: 60px;
  min-height: 28px;
  margin: 0;
  padding: 4px 10px 4px 10px;
  font-size: 16px;
}

.hand-condition:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

.hand-condition:has(input:disabled):hover {
  border-color: var(--color-border);
  background: var(--color-panel);
}

.hand-condition--limited:has(input:disabled):hover {
  background: color-mix(in srgb, var(--color-gold) 10%, var(--color-panel));
}

/* ── 15. Калькулятор — результат ── */

.hand-calculator-result-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  flex-shrink: 0;
}

.hand-calculator-result-top h3 {
  margin: 0;
}

.hand-calculator-result-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  margin: 0px 0px 8px 0px;
}

.hand-calculator-result-controls .hand-limit-field {
  margin: 0;
  white-space: nowrap;
}

.hand-teaching-toggle {
  display: inline-flex;
  flex: 1 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  max-width: 165px;
  margin: 0px 0px 10px;
  padding: 2px 7px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-panel);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.hand-teaching-toggle:hover {
  border-color: color-mix(in srgb, var(--color-teal-accent) 40%, var(--color-border));
  background: color-mix(in srgb, var(--color-teal-accent) 6%, var(--color-panel));
}

.hand-teaching-toggle:has(input:checked) {
  border-color: color-mix(in srgb, var(--color-green) 45%, var(--color-border));
  background: color-mix(in srgb, var(--color-green) 10%, var(--color-panel));
}

.hand-teaching-toggle input {
  margin: 0;
}

.hand-teaching-panel {
  margin-top: 4px;
}

.hand-teaching-steps {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hand-teaching-step {
  padding: 4px 5px;
  margin-left: -6px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.hand-teaching-step__title {
  display: block;
  font-weight: 600;
  font-size: 20px;
}

.hand-teaching-step__description {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  color: var(--color-text-muted, #64748b);
  line-height: 1.45;
}

.hand-teaching-step:hover,
.hand-teaching-step--hover,
.hand-teaching-step--active {
  background: rgb(37 99 235 / 8%);
  border-color: rgb(37 99 235 / 22%);
}

.hand-teaching-step--active {
  box-shadow: inset 3px 0 0 #2563eb;
}

.hand-teaching-highlight {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgb(37 99 235 / 18%);
  z-index: 1;
  position: relative;
}

.hand-calculator-result-score {
  flex-shrink: 0;
  min-width: min(100%, 220px);
}

.hand-calculator-result-score .hand-result-score {
  margin: 0;
}

.hand-result-score--placeholder strong {
  color: var(--color-text-muted);
  font-size: 20px;
}

.hand-result-empty {
margin: 0;
  color: var(--color-text-muted);
  font-size: 13px;
}

.hand-result-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 7px;
  border-radius: 12px;
  background: var(--color-panel);
  color: var(--color-heading);
  font-size: 16px;
  font-weight: bolder;
}

.hand-result-score strong {
  color: var(--color-teal-accent);
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 24px;
}

.hand-result-score--limited strong {
  color: #b45309;
}

.hand-result-limited {
  padding: 12px;
  border: 1px solid rgb(180 83 9 / 35%);
  border-radius: 12px;
  background: color-mix(in srgb, #f59e0b 12%, var(--color-panel));
  color: var(--color-heading);
}

.hand-result-limited strong {
  display: block;
  margin-bottom: 6px;
  color: #b45309;
  font-size: 18px;
}

.hand-result-limited-list {
  margin: 0 0 8px;
  padding-left: 18px;
  font-size: 16px;
  line-height: 1.45;
  overflow: visible;
}

.hand-result-limited-list li {
  overflow: visible;
}

.hand-result-limited p {
  margin: 0;
  font-size: 13px;
}

.hand-result-limited-note {
  margin-top: 6px !important;
  color: var(--color-text-muted);
  font-size: 16px !important;
}

.hand-rule-link {
  color: var(--color-teal);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: help;
}

.hand-rule-link:hover,
.hand-rule-link:focus-visible {
  color: color-mix(in srgb, var(--color-teal) 82%, var(--color-heading));
}

.hand-result-meta {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 600;
}

.hand-result-details-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px 14px;
  align-items: start;
}

.hand-result-panel {
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--color-panel);
  color: var(--color-text);
  font-size: 20px;
  line-height: 1.45;
}

.hand-result-panel__title {
  display: block;
  margin-bottom: 6px;
  color: var(--color-heading);
  font-size: 13px;
}

.hand-result-panel__list span {
  display: block;
  margin-bottom: 4px;
}

.hand-result-panel__list span:last-child {
  margin-bottom: 0;
}

.hand-result-panel__list--chunked {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(3, auto);
  gap: 4px 14px;
  align-items: start;
}

.hand-result-panel__list--chunked span {
  margin-bottom: 0;
}

.hand-result-panel__empty {
  color: var(--color-text-muted);
}

.hand-result-combinations {
  border-left: 3px solid var(--color-gold);
}

.hand-result-doublings {
  border-left: 3px solid var(--color-teal);
}

.hand-result-total {
  border-left: 3px solid var(--color-teal-accent);
}

.hand-result-total--limited {
  border-left-color: #b45309;
}

/* ── 17. Адаптив калькулятора ── */

@media (min-width: 1200px) {
  .modal-content--hand-calculator {
    width: min(94vw, 1360px);
  }
}

@media (min-width: 1600px) {
  .modal-content--hand-calculator {
    width: min(92vw, 1680px);
  }
}

@media (min-width: 961px) {
  .hand-calculator-content {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 0.88fr) minmax(280px, 0.95fr);
    grid-template-rows: minmax(0, auto) minmax(0, 1fr);
    grid-template-areas:
      "left structure result"
      "left conditions result";
    gap: 14px;
    row-gap: 5px;
    align-items: stretch;
  }

  .hand-calculator-left {
    grid-area: left;
    min-height: 0;
    min-height: 570px;
  }

  .hand-calculator-player {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .hand-calculator-structure {
    grid-area: structure;
    max-height: min(55vh, 520px);
    min-height: 0;
    align-self: start;
  }

  .hand-calculator-tiles {
    flex: 1 1 0;
    min-height: 0;
  }

  .hand-calculator-conditions {
    grid-area: conditions;
    max-height: none;
    min-height: 0;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .hand-calculator-panel-scroll,
  .hand-calculator-structure-scroll,
  .hand-calculator-conditions-scroll {
    padding-bottom: 12px;
    scroll-padding-bottom: 12px;
  }

  .hand-calculator-result {
    grid-area: result;
    min-height: 0;
    max-height: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .hand-calculator-result-top {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .hand-calculator-result-controls {
    justify-content: flex-start;
  }

  .hand-calculator-result-score,
  .hand-calculator-result-score .hand-result-score {
    min-width: 0;
  }

  .hand-calculation-details-scroll {
    flex: 1 1 0;
    min-height: 0;
    padding-bottom: 14px;
    scroll-padding-bottom: 14px;
  }

  .hand-calculation-details-body--filled {
    grid-template-columns: minmax(0, 1fr);
  }

  .hand-result-details-columns:not(.hand-result-details-columns--limited),
  .hand-result-details-columns--limited {
    grid-template-columns: minmax(0, 1fr);
  }

  .hand-result-panel__list--chunked {
    grid-auto-flow: row;
    grid-template-rows: none;
  }
}

@media (max-width: 960px) {
  .modal-content--hand-calculator {
    width: min(98vw, 1280px);
    max-width: none;
    padding: 12px;
    height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  .modal-actions--hand-calculator {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }

  .modal-actions--hand-calculator button {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .hand-calculator-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 0 8px;
  }

  .hand-calculator-left {
    flex: 1.25 1 0;
    min-height: min(74vh, 570px);
    overflow: hidden;
  }

  .hand-calculator-tiles {
    flex: 1 1 auto;
    min-height: min(34vh, 260px);
  }

  .hand-calculator-tiles .hand-tile-picker {
    min-height: min(24vh, 180px);
  }

  .hand-calculator-player {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .hand-calculator-structure,
  .hand-calculator-conditions,
  .hand-calculator-result {
    max-height: none;
  }

  .hand-calculator-structure {
    flex: 0 1 auto;
    min-height: 112px;
  }

  .hand-calculator-conditions {
    flex: 1 1 0;
    min-height: 148px;
  }

  .hand-calculator-result {
    flex: 1 1 0;
    min-height: 168px;
  }

  .hand-calculator-result-top {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .hand-calculator-result-controls {
    justify-self: stretch;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px 10px;
  }

  .hand-calculator-result-score {
    min-width: 0;
  }

  .hand-calculator-result-score .hand-result-score {
    width: 100%;
  }

  .hand-calculation-details-scroll {
    flex: 1 1 0;
    min-height: 500px;
  }

  .hand-calculation-details-body--filled .hand-result-details-columns {
    grid-template-columns: minmax(0, 1fr);
  }

  

  

  .hand-group-tiles {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
  }

  .app-select__menu--hand-decomposition {
    max-width: calc(100vw - 12px);
  }

  .app-select__menu--hand-decomposition .app-select__option {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }
}

@media (min-width: 768px) and (max-width: 960px) {
  .hand-calculator-content {
    gap: 12px;
    row-gap: 14px;
    align-items: stretch;
    overflow: auto;
  }

  .hand-calculator-left {
    grid-area: left;
    flex: none;
    overflow: hidden;
  }

  .hand-calculator-tiles {
    flex: 1 1 auto;
    min-height: 200px;
  }

  .hand-calculator-tiles .hand-tile-picker {
    min-height: 150px;
  }

  .hand-calculator-structure {
    grid-area: structure;
    flex: none;
    min-height: 0;
    align-self: stretch;
  }

  .hand-calculator-conditions {
    grid-area: conditions;
    flex: none;
    min-height: 0;
    align-self: stretch;
  }

  .hand-calculator-result {
    grid-area: result;
    flex: none;
    min-height: 180px;
  }

  .hand-calculation-details-body--filled {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hand-calculation-details-body--filled .hand-result-meta,
  .hand-calculation-details-body--filled .hand-result-limited,
  .hand-calculation-details-body--filled .hand-result-details-columns {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767px) {
  .hand-calculator-content {
    gap: 12px;
    row-gap: 14px;
    align-items: stretch;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .hand-calculator-tiles {
    min-height: min(36vh, 280px);
  }

  .hand-calculator-tiles .hand-tile-picker {
    min-height: min(26vh, 200px);
  }

  .hand-calculator-structure {
    flex: 0 1 auto;
    min-height: 108px;
  }

  .hand-calculator-conditions {
    flex: 0.9 1 0;
    min-height: 132px;
  }

  .hand-calculator-result {
    flex: 1 1 0;
    min-height: 500px;
  }

  .hand-calculation-details-body--filled {
    grid-template-columns: minmax(0, 1fr);
  }

  .hand-tile-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    padding: 2px 0 0;
  }

  .hand-tile-grid--honors {
    grid-template-columns:
      repeat(4, minmax(0, 1fr))
      1px
      repeat(3, minmax(0, 1fr))
      1px
      repeat(4, minmax(0, 1fr));
    gap: 3px;
  }

  .hand-tile-group-divider {
    min-height: 0;
  }

  .hand-tile-button {
    width: 41px;
    min-width: 41px;
    max-width: 41px;
    height: 47px;
    max-height: 47px;
  }

  .hand-calculator-section.hand-calculator-tiles {
    --hand-selected-tile-h: clamp(36px, 4.5vw, 44px);
  }

  .hand-section-heading {
    flex-wrap: wrap;
    gap: 8px;
  }

  .hand-section-tools {
    width: 100%;
    justify-content: space-between;
  }

  /* Телефон: единая поверхность прокрутки вместо вложенных панелей */
  .hand-calculator-left,
  .hand-calculator-section.hand-calculator-tiles,
  .hand-calculator-section.hand-calculator-structure,
  .hand-calculator-section.hand-calculator-conditions,
  .hand-calculator-section.hand-calculator-result {
    flex: none;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  .hand-selected-tiles,
  .hand-selected-tiles--grouped {
    max-height: none;
    overflow: visible;
    overscroll-behavior: auto;
  }

  .hand-calculator-tiles .hand-tile-picker,
  .hand-calculator-panel-scroll,
  .hand-calculator-structure-scroll,
  .hand-calculator-conditions-scroll,
  .hand-calculation-details-scroll {
    flex: none;
    min-height: 0;
    max-height: none;
    overflow: visible;
    overscroll-behavior: auto;
  }
}

@media (max-width: 420px) {
  .hand-tile-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .hand-tile-grid--honors {
    grid-template-columns:
      repeat(4, minmax(0, 1fr))
      1px
      repeat(3, minmax(0, 1fr))
      1px
      repeat(4, minmax(0, 1fr));
    gap: 2px;
  }

  .hand-tile-button {
    width: 38px;
    min-width: 38px;
    max-width: 38px;
    height: 44px;
    max-height: 44px;
  }

  .hand-calculator-section.hand-calculator-tiles {
    --hand-selected-tile-h: clamp(34px, 5vw, 40px);
  }

  .hand-calculator-section {
    padding: 6px 10px;
  }

  .hand-calculator-section h3 {
    font-size: 14px;
  }
}

.modal-content--window.modal-content--hand-calculator .modal-actions {
  flex-shrink: 0;
}

/* ── Доступность ── */

@media (prefers-reduced-motion: reduce) {
  .hand-selected-tile--flip .hand-selected-tile__flipper {
    transition: none;
  }
}