.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #061c1a66;
  overscroll-behavior: contain;
}
.custom-modal {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #c1b393;
  border-radius: 6px;
  box-shadow: 0 20px 80px #0006;
}
.custom-modal .modal-header {
  display: flex;
  flex: none;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid #20363125;
  min-height: 60px;
}
.modal-header h2 {
  font-size: 26px;
  line-height: 1.15;
  margin: 0;
  overflow-wrap: anywhere;
}
.modal-header .modal-close {
  margin-left: auto;
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
  color: var(--ink);
  border-color: #20363130;
}
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 24px;
  font-size: 16px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}
.modal-body li {
  margin-bottom: 12px;
}
.modal-body h3 {
  margin-top: 24px;
}
.modal-body a {
  color: #356f61;
}
.modal-body input {
  background: white;
  color: var(--ink);
}
.modal-footer {
  flex: none;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #20363125;
  background: var(--paper);
}
.modal-footer button {
  min-height: 44px;
  border-color: #20363140;
  color: var(--ink);
}
.modal-footer .primary {
  border-color: var(--gold);
}
.toast-host {
  position: fixed;
  z-index: 50;
  bottom: max(16px, env(safe-area-inset-bottom));
  right: max(16px, env(safe-area-inset-right));
  display: grid;
  gap: 10px;
  width: min(480px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: #f4e8c8;
  color: #293c31;
  border: 1px solid #c3a56a;
  box-shadow: 0 8px 30px #0004;
  border-radius: 5px;
  pointer-events: auto;
}
.toast p {
  flex: 1;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.toast-dismiss {
  flex: none;
  color: inherit;
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 24px;
  border-color: #293c3133;
}
.toast[data-tone='error'] {
  border-color: #b34b36;
  background: #f8ded3;
}
@media (max-width: 580px) {
  .modal-overlay {
    padding: 8px;
  }
  .custom-modal .modal-header {
    padding: 10px 14px;
    gap: 8px;
  }
  .modal-header h2 {
    font-size: 22px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-footer {
    padding: 10px 14px;
  }
  .modal-footer button {
    flex: 1;
  }
  .toast-host {
    right: 8px;
    width: calc(100vw - 16px);
  }
}
@media (max-height: 450px) {
  .modal-overlay {
    padding: 6px;
  }
  .custom-modal .modal-header {
    padding: 6px 14px;
    min-height: 48px;
  }
  .modal-header h2 {
    font-size: 20px;
  }
  .modal-footer {
    padding: 6px 14px;
  }
  .modal-body {
    padding: 12px 16px;
  }
}

.dice-modal {
  background: #102b29;
  color: var(--paper);
}
.dice-modal .modal-header,
.dice-modal .modal-footer {
  background: #102b29;
  color: var(--paper);
  border-color: var(--line);
}
.dice-modal .modal-close {
  color: var(--paper);
}
.dice-modal .modal-body {
  padding: 12px;
  min-height: 0;
}
.dice-content {
  height: min(52dvh, 430px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.dice-result {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
}
#diceCanvas {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#diceCanvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.dice-modal[data-outcome='success'] {
  border-color: #9bcc8d;
}
.dice-modal[data-outcome='failure'] {
  border-color: #e8a28b;
}
