:root {
  color-scheme: dark;
  --bg: #080b0d;
  --panel: rgba(17, 23, 24, 0.86);
  --panel-strong: rgba(23, 31, 32, 0.94);
  --line: rgba(225, 218, 190, 0.17);
  --line-bright: rgba(232, 187, 92, 0.52);
  --text: #f3ead8;
  --muted: #a9b7ae;
  --gold: #e8bb5c;
  --jade: #75c7a1;
  --crimson: #c7605a;
  --steel: #8eb0c4;
  --ink: #0e1516;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
  --game-lock-closed: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath fill='%23000' fill-rule='evenodd' d='M9 9h46v46H9zM14 14v36h36V14z'/%3E%3Cpath fill='%23000' d='M17 34h30v16H17zM23 34V25c0-9 7-15 16-15 8 0 14 6 14 14v11h-8V24c0-4-3-7-7-7s-7 3-7 7v10zM28 42a4 4 0 1 1 8 0c0 2-1 3-2 4v4h-4v-4c-1-1-2-2-2-4z'/%3E%3C/svg%3E");
  --game-lock-open: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath fill='%23000' fill-rule='evenodd' d='M9 9h46v46H9zM14 14v36h36V14z'/%3E%3Cpath fill='%23000' d='M17 34h30v16H17zM23 34v-8l23-11c7-3 15 2 15 10v9h-8v-8c0-3-3-5-6-4L31 30v4zM28 42a4 4 0 1 1 8 0c0 2-1 3-2 4v4h-4v-4c-1-1-2-2-2-4z'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(8, 11, 13, 0.34), rgba(8, 11, 13, 0.88)),
    url("assets/forging-bg.png") center / cover no-repeat fixed,
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--jade);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 12px;
}

.topbar,
.overview,
.probability-panel,
.level-panel,
.bottom-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.brand-block h1,
.level-copy h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-block h1 {
  font-size: clamp(1.55rem, 4vw, 2.55rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.session-bar,
.overview,
.level-panel,
.bottom-panel,
.custom-roll,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.session-bar {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 180px;
}

.compact-field {
  min-width: 130px;
}

.field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--text);
  background: rgba(5, 9, 10, 0.72);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%), linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 10px) 18px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.overview {
  padding: 12px;
}

.weapon-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 270px;
}

.weapon-sigil {
  width: 58px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid rgba(232, 187, 92, 0.5);
  border-radius: 50%;
  color: var(--gold);
  background: radial-gradient(circle at 45% 35%, rgba(232, 187, 92, 0.24), rgba(20, 34, 31, 0.68));
  box-shadow: inset 0 0 22px rgba(232, 187, 92, 0.14), 0 0 24px rgba(117, 199, 161, 0.16);
  font-family: Georgia, serif;
  font-size: 1.8rem;
}

.weapon-sigil.aura-ready {
  animation: auraPulse 1800ms ease-in-out infinite;
}

.metric-strip {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(105px, 1fr));
  gap: 10px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 12, 13, 0.66);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
}

.probability-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 14px;
}

.probability-panel span {
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.probability-panel strong {
  color: var(--gold);
}

.level-panel {
  display: grid;
  grid-template-columns: minmax(160px, 0.55fr) 1fr auto;
  padding: 14px;
}

.level-copy h2 {
  font-size: 1.02rem;
}

.level-track {
  position: relative;
  width: 100%;
  height: 38px;
  overflow: hidden;
  border: 1px solid rgba(117, 199, 161, 0.2);
  border-radius: 8px;
  background: rgba(7, 12, 13, 0.72);
}

.level-track-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(117, 199, 161, 0.82), rgba(232, 187, 92, 0.88), rgba(199, 96, 90, 0.72));
  transition: width 260ms ease;
}

.level-marks {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  text-align: right;
  color: rgba(243, 234, 216, 0.76);
  font-size: 0.72rem;
  font-weight: 800;
}

.level-marks span {
  padding-right: 8px;
  border-right: 1px solid rgba(243, 234, 216, 0.2);
}

.level-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

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

.counter-card {
  position: relative;
  min-height: 296px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(26, 35, 36, 0.91), rgba(10, 14, 15, 0.88));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.counter-card.locked {
  border-color: rgba(142, 176, 196, 0.46);
  background: linear-gradient(180deg, rgba(25, 34, 39, 0.94), rgba(10, 14, 17, 0.9));
}

.counter-card.gold-marked {
  border-color: rgba(232, 187, 92, 0.88);
  box-shadow: 0 0 0 1px rgba(232, 187, 92, 0.48), 0 0 24px rgba(232, 187, 92, 0.2), 0 18px 56px rgba(232, 187, 92, 0.14), var(--shadow);
}

.counter-card.locked.gold-marked {
  border-color: rgba(232, 187, 92, 0.78);
}

.counter-card.pity-ready {
  border-color: rgba(232, 187, 92, 0.72);
  box-shadow: 0 0 0 1px rgba(232, 187, 92, 0.22), 0 22px 70px rgba(0, 0, 0, 0.42);
}

.counter-card.gold-marked.pity-ready {
  box-shadow: 0 0 0 1px rgba(232, 187, 92, 0.56), 0 0 30px rgba(232, 187, 92, 0.22), 0 18px 56px rgba(232, 187, 92, 0.14), var(--shadow);
}

.counter-card.locked::after,
.counter-card.unavailable::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(135deg, rgba(142, 176, 196, 0.06), rgba(142, 176, 196, 0.06) 8px, transparent 8px, transparent 18px);
}

.counter-card.unavailable {
  opacity: 0.56;
}

.counter-card.unavailable .gold-btn,
.counter-card.unavailable .lock-btn {
  pointer-events: none;
}

.counter-head {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 8px;
  align-items: center;
}

.part-name {
  flex: 1;
}

.part-name input {
  min-width: 0;
  padding: 0 8px;
  color: var(--text);
  font-weight: 800;
  background: rgba(255, 255, 255, 0.04);
}

.lock-btn {
  width: 46px;
  min-width: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(142, 176, 196, 0.14);
  border-color: rgba(142, 176, 196, 0.28);
}

.lock-btn[aria-pressed="true"] {
  color: #ffe7e4;
  background: rgba(199, 96, 90, 0.42);
  border-color: rgba(199, 96, 90, 0.9);
  box-shadow: inset 0 0 0 1px rgba(255, 231, 228, 0.12), 0 0 0 3px rgba(199, 96, 90, 0.14);
}

.lock-icon {
  width: 28px;
  aspect-ratio: 1;
  display: block;
  background: #c8c9c5;
  -webkit-mask: var(--game-lock-open) center / contain no-repeat;
  mask: var(--game-lock-open) center / contain no-repeat;
}

.lock-btn[aria-pressed="true"] .lock-icon {
  background: #ffe7e4;
  -webkit-mask-image: var(--game-lock-closed);
  mask-image: var(--game-lock-closed);
}

.count-wrap {
  position: relative;
  z-index: 1;
  align-self: center;
  display: grid;
  justify-items: center;
}

.counter-card.locked .count-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: min(42%, 118px);
  aspect-ratio: 1;
  margin: auto;
  background: rgba(255, 231, 228, 0.34);
  -webkit-mask: var(--game-lock-closed) center / contain no-repeat;
  mask: var(--game-lock-closed) center / contain no-repeat;
  pointer-events: none;
  filter: drop-shadow(0 0 18px rgba(0, 0, 0, 0.5));
}

.count-wrap span {
  font-variant-numeric: tabular-nums;
  font-size: clamp(4rem, 9vw, 6.8rem);
  font-weight: 900;
  line-height: 0.85;
  color: var(--text);
  text-shadow: 0 0 32px rgba(232, 187, 92, 0.16);
}

.count-wrap small {
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.counter-card.pity-ready .count-wrap small {
  color: var(--gold);
}

.stat-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.stat-row strong {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.gold-btn {
  position: relative;
  z-index: 1;
  color: #151008;
  font-weight: 900;
  background: linear-gradient(135deg, #f5d783, var(--gold));
  box-shadow: 0 10px 24px rgba(232, 187, 92, 0.2);
}

.bottom-panel {
  position: sticky;
  bottom: 10px;
  justify-content: space-between;
  padding: 12px;
}

.quick-rolls {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr));
  gap: 8px;
}

.roll-btn,
.primary-btn {
  min-width: 54px;
  padding: 0 14px;
  color: #08110f;
  font-weight: 900;
  background: var(--jade);
}

.roll-btn:hover,
.primary-btn:hover {
  box-shadow: 0 0 0 3px rgba(117, 199, 161, 0.18);
}

.secondary-btn {
  padding: 0 14px;
  background: rgba(232, 187, 92, 0.13);
  border-color: rgba(232, 187, 92, 0.35);
}

.ghost-btn {
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}

.history-btn {
  min-width: 72px;
}

.toggle-row {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.danger-btn {
  padding: 0 14px;
  color: #ffe7e4;
  background: rgba(199, 96, 90, 0.16);
  border-color: rgba(199, 96, 90, 0.42);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
}

.switch span {
  width: 46px;
  height: 26px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 10, 11, 0.78);
}

.switch span::before {
  content: "";
  display: block;
  width: 18px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 170ms ease, background 170ms ease;
}

.switch input:checked + span::before {
  transform: translateX(19px);
  background: var(--jade);
}

.stats-hidden .stat-row {
  visibility: hidden;
}

.flash {
  animation: flashGold 520ms ease;
}

.tick {
  animation: tickCount 260ms ease;
}

.unlocked {
  animation: unlockGlow 720ms ease;
}

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

@keyframes flashGold {
  0%,
  100% {
    box-shadow: var(--shadow);
  }
  35% {
    box-shadow: 0 0 0 2px rgba(232, 187, 92, 0.8), 0 0 42px rgba(232, 187, 92, 0.5);
  }
}

@keyframes tickCount {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes unlockGlow {
  0% {
    border-color: var(--jade);
  }
  55% {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(117, 199, 161, 0.42), 0 0 44px rgba(117, 199, 161, 0.25);
  }
  100% {
    border-color: var(--line);
  }
}

@keyframes auraPulse {
  0%,
  100% {
    box-shadow: inset 0 0 22px rgba(232, 187, 92, 0.16), 0 0 24px rgba(117, 199, 161, 0.18);
  }
  50% {
    box-shadow: inset 0 0 26px rgba(232, 187, 92, 0.34), 0 0 38px rgba(117, 199, 161, 0.28);
  }
}

@media (max-width: 920px) {
  .topbar,
  .overview,
  .level-panel,
  .bottom-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .level-panel {
    grid-template-columns: 1fr;
  }

  .metric-strip,
  .probability-panel,
  .counter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bottom-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  body {
    min-height: 100dvh;
    overflow: hidden;
    background-attachment: scroll;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: 6px;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    gap: 6px;
    overflow: hidden;
  }

  .topbar {
    order: 1;
    display: grid;
    grid-template-columns: minmax(78px, 0.36fr) minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
  }

  .brand-block {
    min-width: 0;
    align-self: end;
  }

  .brand-block .eyebrow {
    display: none;
  }

  .brand-block h1 {
    font-size: 0.96rem;
    line-height: 1.05;
  }

  .session-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) repeat(3, 40px);
    align-items: end;
    gap: 5px;
  }

  .overview {
    order: 2;
    display: grid;
    grid-template-columns: minmax(82px, 0.5fr) minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
  }

  .weapon-card {
    align-items: stretch;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
  }

  .weapon-sigil {
    display: none;
  }

  .probability-panel {
    display: none;
  }

  .level-panel {
    order: 3;
    grid-template-columns: minmax(78px, 0.44fr) minmax(0, 1fr) auto;
    gap: 6px;
    padding: 6px;
    align-items: center;
  }

  .level-copy .eyebrow {
    display: none;
  }

  .level-copy h2 {
    font-size: 0.72rem;
    line-height: 1.1;
  }

  .level-track {
    height: 30px;
  }

  .level-marks {
    font-size: 0.58rem;
  }

  .level-marks span {
    padding-right: 4px;
  }

  .level-actions {
    display: grid;
    gap: 3px;
    justify-items: stretch;
    text-align: center;
    white-space: normal;
  }

  .level-actions span {
    font-size: 0.62rem;
    font-weight: 800;
  }

  .bottom-panel {
    order: 5;
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 6px;
  }

  .counter-grid {
    order: 4;
    min-height: 0;
    overflow: hidden;
  }

  .field {
    gap: 2px;
  }

  .field span {
    font-size: 0.56rem;
  }

  input,
  select,
  button {
    min-height: 34px;
    border-radius: 7px;
    padding: 0 7px;
    font-size: 0.74rem;
  }

  select {
    background-position: calc(100% - 12px) 14px, calc(100% - 7px) 14px;
    background-size: 5px 5px, 5px 5px;
  }

  .session-bar,
  .custom-roll,
  .toggle-row,
  .weapon-card {
    width: 100%;
  }

  .field,
  .compact-field,
  .session-bar button,
  .toggle-row button,
  .custom-roll button {
    width: 100%;
    min-width: 0;
  }

  .session-bar button {
    padding: 0 4px;
    font-size: 0.58rem;
  }

  .metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .metric {
    padding: 5px 6px;
  }

  .metric span {
    font-size: 0.54rem;
    line-height: 1.05;
  }

  .metric strong {
    margin-top: 3px;
    font-size: 0.92rem;
  }

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

  .counter-card {
    min-height: 0;
    gap: 4px;
    padding: 6px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }

  .counter-head {
    gap: 5px;
  }

  .part-name input {
    min-height: 30px;
    padding: 0 6px;
    font-size: 0.7rem;
  }

  .lock-btn {
    width: 40px;
    min-width: 40px;
    min-height: 36px;
  }

  .lock-icon {
    width: 22px;
  }

  .count-wrap small {
    margin-top: 4px;
    font-size: 0.54rem;
    line-height: 1.1;
    text-align: center;
  }

  .counter-card.locked .count-wrap::after {
    width: min(38%, 76px);
  }

  .stat-row {
    gap: 3px;
    font-size: 0.57rem;
  }

  .gold-btn {
    min-height: 31px;
  }

  .quick-rolls {
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .roll-btn {
    min-width: 0;
    padding: 0;
  }

  .custom-roll {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 58px;
    align-items: end;
    gap: 5px;
  }

  .custom-roll .field span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .toggle-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .toggle-row button {
    min-height: 32px;
    padding: 0 4px;
    font-size: 0.58rem;
    line-height: 1.05;
    white-space: normal;
  }

  .history-btn {
    min-width: 0;
  }

  .switch {
    justify-content: center;
    min-height: 32px;
    gap: 4px;
    padding: 0 3px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.05);
    font-size: 0.58rem;
  }

  .switch span {
    width: 32px;
    height: 18px;
    padding: 2px;
  }

  .switch span::before {
    width: 12px;
  }

  .switch input:checked + span::before {
    transform: translateX(14px);
  }

  .count-wrap span {
    font-size: clamp(2.2rem, 14vw, 3.55rem);
  }
}

@media (max-height: 560px) and (orientation: landscape) and (max-width: 980px) {
  body {
    min-height: 100dvh;
    overflow: hidden;
    background-attachment: scroll;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: 6px;
    display: grid;
    grid-template-columns: minmax(160px, 0.82fr) minmax(205px, 1.18fr) minmax(140px, 0.72fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px;
    overflow: hidden;
  }

  .topbar,
  .overview,
  .level-panel,
  .bottom-panel,
  .counter-card {
    padding: 6px;
  }

  .topbar {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 6px;
    align-items: end;
  }

  .brand-block {
    min-width: 0;
  }

  .brand-block .eyebrow,
  .probability-panel,
  .weapon-sigil,
  .level-copy .eyebrow {
    display: none;
  }

  .brand-block h1 {
    font-size: 0.82rem;
    line-height: 1.05;
  }

  .session-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) repeat(3, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
  }

  .overview {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
    align-self: stretch;
  }

  .weapon-card {
    width: 100%;
    min-width: 0;
  }

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .metric {
    padding: 4px 5px;
  }

  .metric span {
    font-size: 0.48rem;
    line-height: 1;
  }

  .metric strong {
    margin-top: 1px;
    font-size: 0.78rem;
  }

  .level-panel {
    grid-column: 1;
    grid-row: 3;
    display: grid;
    grid-template-columns: minmax(58px, 0.45fr) minmax(0, 1fr) auto;
    gap: 5px;
    align-items: center;
  }

  .level-copy h2 {
    font-size: 0.62rem;
    line-height: 1.05;
  }

  .level-track {
    height: 27px;
  }

  .level-marks {
    font-size: 0.5rem;
  }

  .level-marks span {
    padding-right: 3px;
  }

  .level-actions {
    display: grid;
    gap: 2px;
    justify-items: stretch;
    text-align: center;
    white-space: normal;
  }

  .level-actions span {
    font-size: 0.52rem;
    font-weight: 800;
  }

  .counter-grid {
    grid-column: 2;
    grid-row: 1 / 4;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 6px;
    min-height: 0;
    overflow: hidden;
  }

  .counter-card {
    min-height: 0;
    gap: 3px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }

  .counter-head {
    gap: 5px;
  }

  .part-name input {
    min-height: 32px;
    padding: 0 6px;
    font-size: 0.67rem;
  }

  .lock-btn {
    width: 38px;
    min-width: 38px;
    min-height: 32px;
  }

  .lock-icon {
    width: 21px;
  }

  .count-wrap span {
    font-size: clamp(1.9rem, 6.4vw, 3.1rem);
  }

  .count-wrap small {
    margin-top: 2px;
    font-size: 0.48rem;
    line-height: 1.05;
    text-align: center;
  }

  .stat-row {
    gap: 3px;
    font-size: 0.52rem;
  }

  .gold-btn {
    min-height: 29px;
  }

  .bottom-panel {
    grid-column: 3;
    grid-row: 1 / 4;
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
    align-content: stretch;
  }

  .quick-rolls {
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  .roll-btn {
    min-width: 0;
    padding: 0;
  }

  .custom-roll {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 4px;
    align-items: end;
  }

  .custom-roll .field span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .toggle-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  .field,
  .compact-field,
  .session-bar button,
  .toggle-row button,
  .custom-roll button {
    width: 100%;
    min-width: 0;
  }

  .field {
    gap: 2px;
  }

  .field span {
    font-size: 0.5rem;
  }

  input,
  select,
  button {
    min-height: 31px;
    border-radius: 7px;
    padding: 0 6px;
    font-size: 0.64rem;
  }

  select {
    background-position: calc(100% - 12px) 13px, calc(100% - 7px) 13px;
    background-size: 5px 5px, 5px 5px;
  }

  .session-bar button,
  .toggle-row button {
    padding: 0 4px;
    line-height: 1.05;
    white-space: normal;
  }

  .switch {
    justify-content: center;
    min-height: 31px;
    gap: 4px;
    padding: 0 3px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.05);
    font-size: 0.58rem;
  }

  .switch span {
    width: 32px;
    height: 18px;
    padding: 2px;
  }

  .switch span::before {
    width: 12px;
  }

  .switch input:checked + span::before {
    transform: translateX(14px);
  }
}

@media (max-width: 560px) and (max-height: 720px) and (orientation: portrait) {
  .app-shell {
    padding: 4px;
    gap: 4px;
  }

  .topbar,
  .overview,
  .level-panel,
  .bottom-panel,
  .counter-card {
    padding: 5px;
  }

  input,
  select,
  button {
    min-height: 31px;
    font-size: 0.68rem;
  }

  .metric {
    padding: 4px 5px;
  }

  .metric span {
    font-size: 0.45rem;
    line-height: 1;
  }

  .metric strong {
    margin-top: 1px;
    font-size: 0.76rem;
  }

  .level-track {
    height: 26px;
  }

  .toggle-row button,
  .switch,
  .gold-btn {
    min-height: 29px;
  }

  .counter-card {
    gap: 3px;
  }

  .count-wrap span {
    font-size: clamp(1.9rem, 13vw, 3.1rem);
  }

  .count-wrap small {
    margin-top: 2px;
    font-size: 0.5rem;
  }
}
