:root {
  color-scheme: light;
  --bg: #fdfdfd;
  --ink: #11172a;
  --muted: #2a3147;
  --soft-muted: #697086;
  --line: #e2e6ef;
  --circle: #fbfcff;
  --circle-border: #e1e5ee;
  --blue: #3f7df1;
  --blue-deep: #2f6fe9;
  --panel: #ffffff;
  --shadow: 0 20px 44px rgb(17 23 42 / 10%), 0 2px 10px rgb(17 23 42 / 5%);
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, #ffffff 0, #ffffff 280px, transparent 520px),
    var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.shell {
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 34px 18px 48px;
}

.masthead {
  margin-bottom: 26px;
  text-align: center;
}

.brand {
  display: flex;
  justify-content: center;
}

.brand-wordmark {
  display: block;
  width: min(100%, 360px);
  height: auto;
  object-fit: contain;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.meta {
  display: none;
}

.sim-title {
  margin-bottom: 14px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}

.winner-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
}

.winner-banner[hidden] {
  display: none !important;
}

.workspace,
.lineup-area {
  min-width: 0;
}

.workspace {
  display: flex;
  flex-direction: column;
}

.status-line {
  margin: -10px 0 18px;
  color: var(--soft-muted);
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
}

.error {
  color: var(--danger);
  font-weight: 700;
}

.slots {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px 18px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 16px 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.slots[hidden],
.my-sims[hidden] {
  display: none !important;
}

.slots::before {
  content: attr(data-title);
  grid-column: 1 / -1;
  justify-self: stretch;
  margin-bottom: 14px;
  background:
    linear-gradient(var(--blue), var(--blue)) left 50% / calc(50% - 70px) 2px no-repeat,
    linear-gradient(var(--blue), var(--blue)) right 50% / calc(50% - 70px) 2px no-repeat;
  color: var(--ink);
  font-size: 22px;
  font-weight: 850;
  line-height: 1.1;
  text-align: center;
}

.slot {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
}

.slot:disabled {
  cursor: default;
}

.slot-circle {
  display: grid;
  place-items: center;
  width: clamp(58px, 17vw, 70px);
  height: clamp(58px, 17vw, 70px);
  border: 1px solid var(--circle-border);
  border-radius: 999px;
  background: var(--circle);
  color: var(--circle-ink, var(--blue));
  box-shadow: 0 8px 18px rgb(17 23 42 / 9%);
  font-size: clamp(18px, 4.4vw, 23px);
  font-weight: 800;
  line-height: 1;
}

.slot.selected .slot-circle {
  border-width: 3px;
}

.slot:focus-visible .slot-circle,
.slot:hover .slot-circle {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.slot-label {
  display: grid;
  justify-items: center;
  width: 100%;
  min-height: 36px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.slot-label > span {
  display: block;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.slot.selected .slot-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 34px;
  order: 2;
}

.actions > :only-child {
  grid-column: 1 / -1;
}

.actions > .primary,
.actions > .secondary,
.actions > .danger {
  min-height: 62px;
  border-radius: 18px;
  font-size: 20px;
}

.primary,
.secondary,
.danger {
  width: 100%;
  min-height: 62px;
  border-radius: 18px;
  padding: 0 18px;
  font-size: 20px;
  font-weight: 800;
}

.primary {
  border: 0;
  background: linear-gradient(180deg, #4d8afa 0%, var(--blue-deep) 100%);
  color: #fff;
  box-shadow: 0 12px 24px rgb(63 125 241 / 22%);
}

.primary:disabled {
  background: linear-gradient(180deg, #8db5fb 0%, #6e99ef 100%);
  color: rgb(255 255 255 / 86%);
  box-shadow: 0 10px 20px rgb(63 125 241 / 14%);
  opacity: 0.72;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 8px 18px rgb(17 23 42 / 7%);
}

.danger {
  border: 2px solid var(--danger);
  background: var(--panel);
  color: var(--danger);
}

.result-area {
  margin-top: 38px;
  order: 1;
}

.workspace.submit-mode .actions {
  order: 1;
}

.workspace.submit-mode .result-area {
  order: 2;
}

.result-area h2 {
  margin-bottom: 14px;
  font-size: 20px;
  font-weight: 850;
}

.my-sims {
  margin-top: 38px;
}

.my-sims h2 {
  margin-bottom: 14px;
  font-size: 20px;
  font-weight: 850;
}

.my-sim-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 12px 28px rgb(17 23 42 / 7%);
}

.my-sim-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.my-sim-row:last-child {
  border-bottom: 0;
}

.my-sim-row:hover,
.my-sim-row:focus-visible {
  background: #f7faff;
  outline: none;
}

.my-sim-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.my-sim-title {
  min-width: 0;
  font-size: 16px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-sim-date {
  min-width: 0;
  color: var(--soft-muted);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-sim-role {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.my-sim-role.created {
  border-color: #b8d7ff;
  background: #edf5ff;
  color: #005bbb;
}

.my-sim-role.participated {
  border-color: #d8d0e8;
  background: #f5f1ff;
  color: #4f2f91;
}

.results-empty {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgb(17 23 42 / 7%);
  text-align: center;
}

.results-empty-title {
  display: block;
  font-size: 18px;
  font-weight: 800;
}

.results-empty-subtitle {
  display: block;
  margin-top: 5px;
  color: var(--soft-muted);
  font-size: 13px;
  font-weight: 700;
}

.not-found {
  display: grid;
  gap: 18px;
  text-align: center;
}

.not-found h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 850;
}

.result-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 12px 28px rgb(17 23 42 / 7%);
}

.result-entry {
  border-bottom: 1px solid var(--line);
}

.result-entry:last-child {
  border-bottom: 0;
}

.result-entry.selected {
  background: #f7faff;
}

.result-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  border: 0;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.result-arrow {
  width: 8px;
  height: 8px;
  border: solid var(--ink);
  border-width: 0 2px 2px 0;
  transform: rotate(-45deg);
}

.result-entry.selected .result-arrow {
  transform: rotate(45deg);
}

.result-nickname,
.result-record {
  font-size: 16px;
  font-weight: 800;
}

.result-record {
  text-align: right;
}

.matchup-badge {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: #fff;
  font-size: 15px;
  font-weight: 900;
}

.matchup-badge.win {
  background: #168447;
}

.matchup-badge.loss {
  background: #b42318;
}

.result-detail {
  display: grid;
  gap: 16px;
  padding: 2px 12px 16px;
}

.detail-section ul {
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  list-style: none;
}

.detail-section li {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.detail-section li:last-child {
  border-bottom: 0;
}

.matchup-list {
  display: grid;
  gap: 12px;
}

.matchup-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 12px 28px rgb(17 23 42 / 7%);
}

.matchup-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.matchup-opponent {
  min-width: 0;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.matchup-record {
  color: var(--soft-muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.matchup-subhead {
  padding: 12px 12px 7px;
  color: var(--soft-muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.matchup-lineup li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.3;
}

.matchup-position {
  color: var(--blue);
  font-weight: 900;
}

.matchup-pair {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.matchup-player {
  min-width: 0;
  overflow-wrap: anywhere;
}

.matchup-player.opponent {
  color: var(--soft-muted);
}

.matchup-vs {
  color: var(--soft-muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.matchup-item ul {
  border: 0;
  border-radius: 0;
}

.matchup-games li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px auto;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}

.game-result {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.game-result.win {
  background: #137333;
}

.game-result.loss {
  background: #b42318;
}

.search-dialog {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translateX(-50%);
  width: min(430px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  height: min(760px, calc(100dvh - env(safe-area-inset-top) - 24px));
  max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  padding: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.nickname-dialog {
  width: min(360px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.nickname-dialog::backdrop {
  background: rgb(17 23 42 / 42%);
}

.nickname-panel {
  display: grid;
  gap: 14px;
  padding: 24px;
}

.nickname-panel h2 {
  margin-bottom: 0;
  font-size: 24px;
  text-align: center;
}

.details-field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.details-field[hidden] {
  display: none !important;
}

.nickname-input {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  background: #fbfcff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 90%);
  font-size: 16px;
}

.nickname-input:focus {
  border-color: var(--blue);
  outline: none;
}

#participant-count-input {
  -moz-appearance: textfield;
  appearance: textfield;
}

#participant-count-input::-webkit-inner-spin-button,
#participant-count-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.nickname-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.search-dialog::backdrop {
  background: rgb(17 23 42 / 42%);
}

.search-panel {
  display: grid;
  gap: 18px;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  height: 100%;
  max-height: none;
  overflow: hidden;
  padding: 24px;
  background: var(--panel);
}

.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-top h2 {
  min-width: 0;
  margin-bottom: 0;
  font-size: 24px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-size: 30px;
  font-weight: 500;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--blue);
  outline: none;
}

.search-input-wrap {
  position: relative;
  min-width: 0;
}

.search-input {
  min-width: 0;
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 44px 0 14px;
  background: #fbfcff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 90%);
}

.search-input:focus {
  border-color: var(--blue);
  outline: none;
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 10px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  padding: 0;
  transform: translateY(-50%);
  background: transparent;
  color: #707070;
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}

.search-clear[hidden] {
  display: none;
}

.search-clear:hover,
.search-clear:focus-visible {
  color: var(--ink);
  outline: none;
}

.search-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.filter-select {
  appearance: none;
  min-width: 0;
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 34px 0 12px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23050505' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    right 10px center / 18px 18px no-repeat,
    #fbfcff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.filter-select:focus {
  border-color: var(--blue);
  outline: none;
}

.results {
  display: grid;
  align-content: start;
  grid-auto-rows: 92px;
  gap: 8px;
  min-height: 0;
  max-height: none;
  margin-right: -8px;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 10px;
  scrollbar-gutter: stable;
}

.results::-webkit-scrollbar {
  width: 10px;
}

.results::-webkit-scrollbar-track {
  background: transparent;
}

.results::-webkit-scrollbar-thumb {
  border: 2px solid var(--panel);
  border-radius: 999px;
  background: #c8d2e7;
}

.result-button {
  appearance: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
  background: #fbfcff;
  color: var(--ink);
  text-align: left;
  box-shadow: 0 6px 14px rgb(17 23 42 / 5%);
}

.result-button:hover,
.result-button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 8px 18px rgb(63 125 241 / 14%);
  outline: none;
}

.result-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
  overflow: hidden;
}

.result-main {
  line-height: 1.16;
  font-weight: 800;
  overflow-wrap: anywhere;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.result-sub,
.result-stats {
  color: var(--soft-muted);
  font-size: 13px;
  line-height: 1.25;
}

.result-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-stats {
  display: grid;
  gap: 2px;
  justify-self: end;
  justify-items: end;
  text-align: right;
}

.result-stats > span {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 4px;
}

.result-stats strong {
  color: var(--ink);
  font-weight: 800;
}

@media (max-width: 380px) {
  .shell {
    padding-inline: 12px;
  }

  .slots {
    gap: 12px 10px;
    padding-inline: 12px;
  }

  .slot-label {
    font-size: 11px;
  }
}

@media (max-width: 520px) {
  .shell {
    padding-top: 28px;
  }

  .slots {
    border-radius: 20px;
    padding: 24px 14px 20px;
  }

  .slots::before {
    margin-bottom: 12px;
    background:
      linear-gradient(var(--blue), var(--blue)) left 50% / calc(50% - 62px) 2px no-repeat,
      linear-gradient(var(--blue), var(--blue)) right 50% / calc(50% - 62px) 2px no-repeat;
    font-size: 20px;
  }

  .slot {
    gap: 10px;
  }

  .slot-circle {
    width: clamp(52px, 16vw, 62px);
    height: clamp(52px, 16vw, 62px);
    font-size: clamp(16px, 4.6vw, 19px);
  }

  .slot-label {
    min-height: 34px;
    font-size: 12px;
  }

  .actions {
    margin-top: 36px;
  }

  .primary,
  .secondary,
  .danger {
    min-height: 58px;
    border-radius: 17px;
    font-size: 18px;
  }

  .actions > .primary,
  .actions > .secondary,
  .actions > .danger {
    min-height: 58px;
    border-radius: 18px;
    font-size: 18px;
  }

  .search-panel {
    gap: 14px;
    padding: 16px;
  }

  .search-filters {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .search-filters .filter-select:last-child {
    grid-column: 1 / -1;
  }

  .filter-select {
    padding-right: 32px;
    font-size: 13px;
  }

  .result-stats {
    font-size: 12px;
  }
}
