.layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: flex-end;
  overflow: hidden;
  animation: fade-in 0.22s ease both;
}

.layer-scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: default;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.drawer {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(820px, 95vw);
  height: 100%;
  border-left: 1px solid var(--line-strong);
  background: var(--bg-elevated);
  box-shadow: -30px 0 80px var(--shadow-strong);
  animation: drawer-in 0.34s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.drawer-head {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: clamp(22px, 3vw, 34px) clamp(20px, 3.5vw, 40px) 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
  font-size: clamp(24px, 3.2vw, 34px);
  font-weight: 300;
  letter-spacing: -0.055em;
  line-height: 1.05;
}

.drawer-close {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.25s ease;
}

.drawer-close:hover {
  border-color: var(--text);
  color: var(--text);
  transform: rotate(90deg);
}

.drawer-close svg {
  width: 16px;
  height: 16px;
}

.rules-drawer {
  width: min(900px, 96vw);
}

.rules-note {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 clamp(20px, 3.5vw, 40px);
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.rules-note > div {
  display: flex;
  gap: 10px;
  padding-right: 22px;
}

.rules-note > div + div {
  padding-right: 0;
  padding-left: 22px;
  border-left: 1px solid var(--line);
}

.rules-note span {
  flex: 0 0 auto;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.06em;
}

.rules-note p {
  color: var(--muted);
  font-size: 8.5px;
  line-height: 1.5;
}

.rules-toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 16px;
  padding: 13px clamp(20px, 3.5vw, 40px);
}

.search-field {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  max-width: 330px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  transition: border-color 0.2s ease;
}

.search-field:focus-within {
  border-color: var(--line-strong);
}

.search-field svg {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  color: var(--faint);
}

.search-field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.02em;
}

.search-field input::placeholder {
  color: var(--faint);
}

.search-field input::-webkit-search-cancel-button {
  display: none;
}

.rules-count {
  margin-left: auto;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 6px;
  letter-spacing: 0.09em;
}

.rules-body {
  display: grid;
  flex: 1;
  grid-template-columns: 196px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
}

.rule-index {
  overflow-y: auto;
  padding: 10px 8px 24px 14px;
  border-right: 1px solid var(--line);
}

.rule-index-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 35px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--faint);
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.rule-index-button svg {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
}

.rule-index-button span {
  overflow: hidden;
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-index-button:hover {
  background: var(--surface);
  color: var(--text-soft);
}

.rule-index-button[aria-current="true"] {
  border-color: var(--line);
  background: var(--surface-raised);
  color: var(--text);
}

.rule-detail {
  overflow-y: auto;
  padding: clamp(20px, 3vw, 32px) clamp(20px, 3.5vw, 36px) 42px;
}

.rule-hero {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.rule-hero-glyph {
  display: grid;
  flex: 0 0 auto;
  width: clamp(70px, 9vw, 96px);
  height: clamp(70px, 9vw, 96px);
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
}

.rule-hero-glyph svg {
  width: 58%;
  height: 58%;
}

.rule-hero-copy {
  min-width: 0;
}

.rule-hero-copy h3 {
  margin-top: 3px;
  font-size: clamp(27px, 4vw, 39px);
  font-weight: 300;
  letter-spacing: -0.06em;
  line-height: 1;
}

.rule-hero-copy p {
  max-width: 470px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.rule-tag {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 6px;
  letter-spacing: 0.11em;
}

.rule-special {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.5;
}

.rule-special::before {
  flex: 0 0 auto;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 6px;
  letter-spacing: 0.06em;
  content: "SPECIAL";
}

.rule-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(18px, 3vw, 34px);
  margin-top: 22px;
}

.rule-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.1em;
}

.rule-column-head strong {
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.03em;
}

.rule-list {
  display: grid;
  gap: 1px;
  margin-top: 5px;
}

.rule-list-empty {
  padding: 10px 0;
  color: var(--faint);
  font-size: 8px;
  font-style: italic;
}

.rule-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 29px;
  padding: 3px 5px;
  border-radius: 4px;
  color: var(--muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.rule-list-item:hover {
  background: var(--surface);
  color: var(--text);
}

.rule-list-item svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}

.rule-list-item span {
  overflow: hidden;
  font-size: 8.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-list-item small {
  margin-left: auto;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.rules-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 250px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.04em;
  text-align: center;
}

.record-drawer {
  width: min(590px, 95vw);
}

.record-content {
  flex: 1;
  overflow-y: auto;
  padding: clamp(20px, 3vw, 32px) clamp(20px, 3.5vw, 36px) 44px;
}

.record-overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.record-stat {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 86px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.record-stat span {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.08em;
}

.record-stat strong {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: clamp(23px, 4vw, 33px);
  font-weight: 400;
  letter-spacing: -0.07em;
  line-height: 1;
}

.record-stat small {
  margin-top: 3px;
  color: var(--faint);
  font-size: 7px;
}

.record-section {
  margin-top: 27px;
}

.record-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.record-section-head h3 {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 6.5px;
  font-weight: 400;
  letter-spacing: 0.1em;
}

.record-section-head button {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.06em;
  transition: color 0.2s ease;
}

.record-section-head button:hover {
  color: var(--text);
}

.record-split {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.record-split-item {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.record-split-item span {
  display: block;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5px;
  letter-spacing: 0.08em;
}

.record-split-item strong {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.04em;
}

.record-list {
  display: grid;
  gap: 0;
  margin-top: 2px;
}

.record-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
}

.record-result {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.05em;
}

.record-row[data-outcome="win"] .record-result {
  color: var(--text);
}

.record-row[data-outcome="loss"] .record-result {
  color: var(--faint);
}

.record-pair {
  overflow: hidden;
  color: var(--muted);
  font-size: 8.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-pair em {
  padding: 0 4px;
  color: var(--faint);
  font-style: normal;
}

.record-meta {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5px;
  letter-spacing: 0.03em;
  text-align: right;
  white-space: nowrap;
}

.record-empty {
  padding: 26px 0 12px;
  color: var(--faint);
  font-size: 9px;
  font-style: italic;
  text-align: center;
}

.record-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 8px;
}

.record-form-item {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.record-form-item svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.record-form-copy {
  min-width: 0;
}

.record-form-copy strong {
  display: block;
  overflow: hidden;
  font-size: 8px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-form-copy span {
  display: block;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5px;
}

.roster-drawer {
  width: min(740px, 96vw);
}

.roster-toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 13px clamp(20px, 3.5vw, 36px);
  border-bottom: 1px solid var(--line);
}

.roster-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.roster-count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 6px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.roster-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  align-content: start;
  overflow-y: auto;
  padding: 16px clamp(20px, 3.5vw, 36px) 22px;
}

.roster-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 105px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--faint);
  text-align: left;
  transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}

.roster-item:hover {
  border-color: var(--line-strong);
  color: var(--text-soft);
}

.roster-item[aria-pressed="true"] {
  border-color: var(--line-strong);
  background: var(--surface-raised);
  color: var(--text);
}

.roster-item::after {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 11px;
  height: 11px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  content: "";
}

.roster-item[aria-pressed="true"]::after {
  border-color: var(--text);
  background:
    linear-gradient(45deg, transparent 42%, var(--bg) 42%, var(--bg) 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--bg) 42%, var(--bg) 58%, transparent 58%),
    var(--text);
}

.roster-item svg {
  width: 33px;
  height: 33px;
}

.roster-item strong {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.roster-item span {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5px;
  letter-spacing: 0.04em;
}

.roster-foot {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px clamp(20px, 3.5vw, 36px);
  border-top: 1px solid var(--line);
  background: var(--bg-elevated);
}

.roster-foot p {
  color: var(--faint);
  font-size: 8px;
}

.roster-foot p.is-warning {
  color: var(--text);
}

.roster-foot-actions {
  display: flex;
  gap: 7px;
}

.roster-foot .secondary-button {
  min-height: 37px;
  padding: 0 15px;
}

#endLayer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.end-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}

.end-card {
  position: relative;
  z-index: 1;
  width: min(470px, 100%);
  padding: clamp(24px, 4vw, 40px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: 0 32px 100px var(--shadow-strong);
  text-align: center;
  animation: end-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.end-mark {
  display: grid;
  width: 66px;
  height: 66px;
  margin: 0 auto 18px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.end-mark svg {
  width: 39px;
  height: 39px;
  animation: slow-spin 22s linear infinite;
}

.end-card .section-kicker {
  margin-bottom: 9px;
}

.end-card h2 {
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 300;
  letter-spacing: -0.06em;
  line-height: 1.02;
}

.end-copy {
  max-width: 340px;
  margin: 11px auto 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 24px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.end-stat {
  padding: 9px 4px;
  border-right: 1px solid var(--line);
}

.end-stat:last-child {
  border-right: 0;
}

.end-stat span {
  display: block;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: 0.08em;
}

.end-stat strong {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: -0.05em;
}

.end-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 12px;
}

.end-actions .primary-button {
  min-height: 45px;
  font-size: 7.5px;
}

.end-actions .secondary-button {
  min-height: 45px;
  font-size: 7px;
}

.toast-region {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(340px, calc(100vw - 30px));
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 39px;
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--glass);
  box-shadow: 0 10px 30px var(--shadow);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.02em;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  animation: toast-in 0.25s ease both;
}

.toast::before {
  flex: 0 0 auto;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  content: "";
  background: var(--text);
}

.toast.is-leaving {
  animation: toast-out 0.2s ease both;
}

.toast.is-warning::before {
  border: 1px solid var(--text);
  background: transparent;
}

@media (max-width: 720px) {
  .drawer {
    width: 100%;
    max-width: 100%;
    border-left: 0;
  }

  .drawer-head {
    padding-top: 20px;
  }

  .rules-note {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .rules-note > div,
  .rules-note > div + div {
    padding: 0;
    border: 0;
  }

  .rules-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .search-field {
    max-width: none;
  }

  .rules-body {
    grid-template-columns: 1fr;
  }

  .rule-index {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rule-index-button {
    flex: 0 0 auto;
    width: 35px;
    min-height: 32px;
    justify-content: center;
    padding: 4px;
  }

  .rule-index-button span {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
  }

  .rule-index-button svg {
    width: 20px;
    height: 20px;
  }

  .rule-detail {
    padding: 20px 16px 40px;
  }

  .rule-columns {
    gap: 18px;
  }

  .roster-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .roster-foot {
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }

  .roster-foot-actions {
    width: 100%;
  }

  .roster-foot-actions > * {
    flex: 1;
  }
}

@media (max-width: 520px) {
  .drawer-head h2 {
    font-size: 25px;
  }

  .rules-note p {
    font-size: 8px;
  }

  .rule-hero {
    gap: 13px;
  }

  .rule-hero-glyph {
    width: 62px;
    height: 62px;
  }

  .rule-columns {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .record-overview {
    grid-template-columns: 1fr 1fr;
  }

  .record-stat {
    min-height: 78px;
  }

  .record-stat:nth-child(3) {
    grid-column: 1 / -1;
    min-height: 66px;
  }

  .record-split {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
  }

  .record-split-item {
    padding: 7px;
  }

  .record-form {
    grid-template-columns: 1fr 1fr;
  }

  .roster-grid {
    grid-template-columns: repeat(2, 1fr);
    padding-right: 14px;
    padding-left: 14px;
  }

  .roster-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .roster-actions {
    width: 100%;
  }

  .roster-actions .mini-button {
    flex: 1;
  }

  .end-actions {
    grid-template-columns: 1fr;
  }

  .record-row {
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 5px 0;
  }

  .record-meta {
    display: none;
  }
}
