.heading-actions {
  flex: 0 0 auto;
}

.view-switch {
  display: flex;
  width: fit-content;
  max-width: 100%;
  gap: 4px;
  margin-bottom: 20px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #151524;
}

.view-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 6px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .83rem;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.view-switch button svg {
  flex: 0 0 auto;
}

.view-switch button:hover {
  color: var(--text);
}

.view-switch button[aria-pressed="true"] {
  border-color: #3a3453;
  background: #27243d;
  color: #eee7ff;
  box-shadow: 0 2px 6px #08081255;
}

.view-switch button[aria-pressed="true"] svg {
  color: var(--violet);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(13px, 1.45vw, 22px);
}

.level-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  transition: border-color 150ms, box-shadow 150ms;
}

.level-card:hover,
.level-card:focus-within {
  border-color: #494165;
  box-shadow: 0 8px 26px #07071233;
}

.level-art {
  position: relative;
  aspect-ratio: 2.05;
  border-bottom: 1px solid var(--line);
  background: #101329;
}

.level-art canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.level-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 7px;
  border: 1px solid #b5a2f337;
  border-radius: 5px;
  background: #0c1020eb;
  color: #ddd0ff;
  font-size: .62rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: .065em;
  text-transform: uppercase;
  pointer-events: none;
}

.level-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px;
}

.level-card-body h2,
.order-panel h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.03rem;
  font-weight: 750;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.level-card-body p,
.order-panel > p {
  margin: 5px 0 14px;
  color: var(--muted);
  font-size: .81rem;
  line-height: 1.5;
}

.level-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: auto;
}

.level-card-actions .icon-button {
  align-self: stretch;
  height: auto;
}

.order-layout,
.editor-layout {
  display: grid;
  align-items: start;
  gap: clamp(14px, 2vw, 24px);
}

.order-layout {
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
}

.order-panel,
.editor-board-panel,
.editor-tools-panel {
  min-width: 0;
  padding: clamp(14px, 2vw, 24px);
}

.order-panel h2 {
  font-size: 1.17rem;
}

.order-panel > p:last-child {
  margin-bottom: 0;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.order-row {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 13px);
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #151626;
}

.order-row canvas {
  display: block;
  flex: 0 0 auto;
  width: clamp(43px, 6vw, 84px);
  height: auto;
  aspect-ratio: 1.65;
  border: 1px solid #32354d;
  border-radius: 5px;
}

.order-number {
  min-width: 1.6em;
  color: var(--violet);
  font-size: .73rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.order-name {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 2px;
  overflow-wrap: anywhere;
}

.order-name strong {
  font-size: .84rem;
  line-height: 1.2;
}

.order-name span {
  color: var(--muted);
  font-size: .73rem;
}

.order-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

.order-actions .icon-button {
  width: 34px;
  height: 34px;
  min-width: 0;
  min-height: 0;
  padding: 0;
}

.order-actions [data-action="order-remove"]:not(:disabled):hover {
  border-color: #804155;
  color: #ffa5b5;
}

.editor-layout {
  grid-template-columns: minmax(0, 1fr) minmax(270px, 340px);
}

.editor-board-top,
.editor-board-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.editor-board-top {
  margin-bottom: 14px;
}

.editor-board-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-board-actions .button {
  min-height: 35px;
  padding: 6px 9px;
  font-size: .77rem;
}

.editor-board-top [aria-pressed="true"] {
  border-color: #7461aa;
  background: #31294b;
  color: #f2eaff;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: clamp(2px, .4vw, 5px);
  padding: clamp(7px, 1vw, 13px);
  border: 1px solid #303451;
  border-radius: 9px;
  background: linear-gradient(160deg, #11172c, #0e1223);
  box-shadow: inset 0 0 24px #080a1955;
  touch-action: none;
  user-select: none;
}

.editor-cell {
  position: relative;
  min-width: 0;
  min-height: 14px;
  aspect-ratio: 1.95;
  padding: 0;
  border: 1px solid #333957;
  border-radius: 3px;
  background: #1b213a;
  cursor: crosshair;
}

.editor-cell:hover {
  border-color: #8f7bc3;
  background: #2b2d48;
}

.editor-cell:focus-visible {
  z-index: 1;
  outline: 2px solid #c7b8ff;
  outline-offset: 1px;
}

.brick-chip {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 24px;
  height: 14px;
  border: 1px solid var(--metal-top, var(--chip-top));
  border-radius: 3px;
  background: linear-gradient(180deg, var(--metal-top, var(--chip-top)), var(--metal-base, var(--chip-base)) 38%, var(--metal-shadow, var(--chip-shadow)));
  color: #101222;
  font: 800 10px/1 system-ui, sans-serif;
  letter-spacing: .02em;
  pointer-events: none;
}

.editor-cell .brick-chip {
  position: absolute;
  inset: -1px;
  width: auto;
  height: auto;
  border-radius: inherit;
}

.editor-cell:hover .brick-chip {
  filter: brightness(1.13);
}

.brick-chip[data-brick="hidden"] {
  border-style: dashed;
  background: #463560;
  color: #ede0ff;
}

.brick-chip[data-brick="gray"] {
  --metal-top: #bec8db;
  --metal-base: #7c8ba6;
  --metal-shadow: #404c61;
}

.brick-chip[data-brick="silver"] {
  --metal-top: #e4edff;
  --metal-base: #a8bad5;
  --metal-shadow: #586b89;
}

.brick-chip[data-brick="steel"] {
  --metal-top: #ccd9ef;
  --metal-base: #8096b7;
  --metal-shadow: #3b4e6c;
}

.brick-chip[data-brick="gold"],
.brick-chip[data-brick="cracked"] {
  --metal-top: #ffe993;
  --metal-base: #d9a52b;
  --metal-shadow: #79510e;
}

.editor-board-bottom {
  margin-top: 15px;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
  cursor: pointer;
}

.check-label input {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
}

.editor-tools-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-label {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-size: .86rem;
  font-weight: 675;
}

.input-label input {
  min-width: 0;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #3b3b55;
  border-radius: 8px;
  background: #121323;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
}

.input-label input::placeholder {
  color: #9492ac;
}

.input-label input[aria-invalid="true"] {
  border-color: #dc7889;
}

.tile-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.tile-field legend {
  margin: 0 0 8px;
  padding: 0;
  color: var(--text);
  font-size: .86rem;
  font-weight: 675;
}

.type-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.type-tools button,
.color-tools button {
  border: 1px solid #363650;
  border-radius: 7px;
  background: #151525;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.type-tools button {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 35px;
  padding: 5px 7px;
  font-size: .75rem;
  font-weight: 600;
  text-align: left;
}

.type-tools button span:not(.brick-chip) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.type-tools button:hover,
.color-tools button:not(:disabled):hover {
  border-color: #726393;
  color: #eae2fb;
}

.type-tools button[aria-pressed="true"],
.color-tools button[aria-pressed="true"] {
  border-color: #997bc9;
  background: #302746;
  color: #f5edff;
}

.color-tools {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
}

.color-tools button {
  position: relative;
  display: grid;
  place-items: stretch;
  min-width: 0;
  min-height: 30px;
  padding: 4px;
}

.color-tools button::before {
  width: 100%;
  min-height: 15px;
  border-radius: 3px;
  background: var(--paint);
  box-shadow: inset 0 1px 1px #fff7;
  content: "";
}

.color-tools button:disabled {
  opacity: .4;
  cursor: default;
}

.form-error {
  margin: 0;
  color: #ffa0af;
  font-size: .8rem;
  line-height: 1.45;
}

.form-error:empty {
  display: none;
}

.editor-submit {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.editor-submit .button {
  flex: 1 0 auto;
  justify-content: center;
}

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}

.privacy-note svg {
  flex: 0 0 auto;
  color: var(--violet);
}

.latest-score {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 250px) auto;
  align-items: center;
  gap: clamp(8px, 1.5vw, 16px);
  margin-bottom: 18px;
  padding: clamp(14px, 1.9vw, 21px);
  border-color: #4b395c;
  background: linear-gradient(100deg, #2a223b, var(--panel) 65%);
}

.latest-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.latest-title > div {
  display: grid;
  gap: 3px;
}

.latest-title > div span {
  color: var(--muted);
  font-size: .8rem;
}

.latest-title .overlay-medal {
  flex: 0 0 auto;
}

.score-table-panel {
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

.table-scroll table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table-scroll th,
.table-scroll td {
  padding: 14px clamp(9px, 1.6vw, 22px);
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.table-scroll th {
  background: #1e1d30;
  color: var(--muted);
  font-size: .71rem;
  font-weight: 740;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.table-scroll td {
  font-size: .857rem;
}

.table-scroll tr:last-child td {
  border-bottom: 0;
}

.table-scroll tr.latest-row td {
  background: #26223a;
}

.table-scroll th:first-child,
.table-scroll td:first-child {
  width: 1%;
}

.table-scroll th:last-child,
.table-scroll td:last-child {
  text-align: right;
}

.table-scroll small,
.table-scroll time {
  color: var(--muted);
  font-size: .76rem;
}

.table-scroll small {
  display: block;
  margin-top: 3px;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 48px;
  min-height: 29px;
  padding: 3px 5px;
  border: 1px solid #37334f;
  border-radius: 6px;
  background: #252439;
  color: #bcb2e0;
  font-size: .76rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.rank-1 {
  border-color: #615036;
  background: #302637;
  color: #ffcf79;
}

.table-score {
  color: #ffa284;
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-scores {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 360px;
  padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 35%, #251f3b, var(--panel) 68%);
  text-align: center;
}

.empty-trophy {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  margin-bottom: 17px;
  border: 1px solid #5d4a61;
  border-radius: 17px;
  background: linear-gradient(145deg, #3b2d4b, #2a233a);
  box-shadow: 0 5px 24px #1712257a;
  color: #ffc689;
}

.empty-scores h2 {
  margin: 0;
  font-size: 1.27rem;
}

.empty-scores p {
  max-width: 33ch;
  margin: 5px 0 22px;
  color: var(--muted);
  font-size: .88rem;
}

#guide {
  width: min(800px, calc(100% - 32px));
  max-width: none;
  max-height: min(720px, calc(100dvh - 32px));
  padding: 0;
  overflow: hidden;
  border: 1px solid #4a405e;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 22px 74px #060612b8;
  color: var(--text);
}

#guide[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#guide::backdrop {
  background: #080912c9;
  backdrop-filter: blur(3px);
}

.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px clamp(14px, 3vw, 24px);
  border-bottom: 1px solid var(--line);
  background: #221f34;
}

.guide-head h2 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.2;
}

.guide-body {
  min-height: 0;
  padding: 17px clamp(14px, 3vw, 24px) 24px;
  overflow: auto;
  overscroll-behavior: contain;
}

.guide-body > p,
.guide-grid p {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.5;
}

.guide-body h3 {
  margin: 18px 0 7px;
  color: var(--text);
  font-size: .98rem;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.guide-grid li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161627;
}

.guide-grid .brick-chip {
  width: 27px;
  margin-top: 2px;
}

.guide-grid strong {
  display: block;
  margin-bottom: 3px;
  color: #f5f0fb;
  font-size: .84rem;
}

.power-chip {
  display: grid;
  flex: 0 0 27px;
  place-items: center;
  min-height: 24px;
  border: 1px solid #47758f;
  border-radius: 5px;
  background: #22475e;
  color: #c5f2ff;
  font-size: .94rem;
  font-weight: 800;
  line-height: 1;
}

.power-chip[data-kind="neutral"] {
  border-color: #676683;
  background: #343448;
  color: #dedcec;
}

.power-chip[data-kind="bad"] {
  border-color: #935268;
  background: #482736;
  color: #ff9eb8;
}

@media (max-width: 1120px) {
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 850px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 780px) {
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 590px) {
  .latest-score { grid-template-columns: minmax(0, 1fr) auto; }
  .latest-title { grid-column: 1 / -1; }
  .table-scroll th:nth-child(4), .table-scroll td:nth-child(4) { display: none; }
  .guide-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 470px) {
  .view-switch { width: 100%; }
  .view-switch button { flex: 1; padding-inline: 6px; }
  .level-grid { grid-template-columns: minmax(0, 1fr); }
  .level-art { aspect-ratio: 2.25; }
  .order-actions .icon-button { width: 31px; height: 33px; }
  .editor-board-actions .button { padding-inline: 7px; }
}
