.ruins-map-page .ruins-map-content {
  max-width: none;
  padding-right: 20px;
}

.ruins-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin: 0 0 8px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.ruins-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.ruins-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.ruins-btn:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.ruins-btn.is-active {
  border-color: var(--sidebar-active);
  background: rgba(41, 171, 224, 0.15);
  color: #0f4c75;
}

.ruins-btn-danger:hover {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}

.ruins-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.ruins-filter select,
.ruins-map-modal-edit select {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  color: var(--text);
}

.ruins-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.ruins-share-status {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 0.85rem;
  word-break: break-all;
}

.ruins-share-status.is-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.ruins-stage-wrap {
  min-width: 0;
  width: 100%;
}

.ruins-stage {
  --guild-UtR: #22c55e;
  --guild-ATK: #ef4444;
  --guild-SOL: #3b82f6;
  --guild-EXP: #a855f7;
  --guild-BAD: #f59e0b;
  --guild-none: #94a3b8;
  --guild-mine-glow: #86efac;

  position: relative;
  width: 100%;
  max-width: none;
  margin: 0;
  aspect-ratio: 1 / 1;
  background-color: #e8eef5;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  user-select: none;
  touch-action: none;
}

.ruins-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ruins-stage[data-mode="draw"] .section-poly {
  pointer-events: none;
}

.ruins-overlay .section-poly {
  fill-opacity: 1;
  stroke-width: 0.003;
  cursor: pointer;
  transition: fill-opacity 0.12s ease, stroke-width 0.12s ease;
}

.ruins-stage.has-map-image .section-poly {
  fill-opacity: 0.38;
}

.ruins-overlay .section-poly.is-owned {
  stroke-width: 0.004;
}

.ruins-stage.has-map-image .section-poly.is-owned {
  fill-opacity: 0.58;
}

.ruins-overlay .section-poly.is-castle-empty {
  fill-opacity: 0;
  stroke-width: 0.0035;
  stroke-dasharray: 0.012 0.008;
}

.ruins-overlay .section-poly:hover,
.ruins-overlay .section-poly.is-hovered,
.ruins-overlay .section-poly.is-selected {
  stroke-width: 0.008;
}

.ruins-overlay .section-poly.is-castle-empty:hover,
.ruins-overlay .section-poly.is-castle-empty.is-hovered,
.ruins-overlay .section-poly.is-castle-empty.is-selected {
  fill-opacity: 0.08;
  fill: #64748b;
}

.ruins-overlay .section-poly.is-mine {
  stroke: #0f172a;
  stroke-width: 0.01;
}

.ruins-overlay .section-poly.is-dimmed {
  fill-opacity: 0.25;
  stroke-opacity: 0.3;
}

.ruins-overlay .section-castle-icon {
  pointer-events: none;
}

.ruins-overlay .section-label {
  fill: #fff;
  font-size: 0.032px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 0.004px;
}

.ruins-overlay .section-label.is-light {
  fill: #0f172a;
  stroke: rgba(255, 255, 255, 0.45);
}

.ruins-map-modal {
  position: absolute;
  z-index: 5;
  min-width: 200px;
  max-width: min(320px, 78%);
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
}

.ruins-map-modal.is-editing {
  pointer-events: auto;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%);
  min-width: min(360px, 86%);
  max-width: min(420px, 90%);
  max-height: min(80%, 520px);
  overflow: auto;
  padding: 18px 44px 18px 20px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.45);
}

.ruins-map-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.ruins-map-modal-close:hover {
  background: rgba(148, 163, 184, 0.2);
  color: #fff;
}

.ruins-map-modal-close[hidden] {
  display: none;
}

.ruins-map-modal[hidden] {
  display: none;
}

.ruins-map-modal-level {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #93c5fd;
}

.ruins-map-modal-name {
  margin: 0 0 6px;
  font-size: 1.05rem;
  line-height: 1.25;
}

.ruins-map-modal-id {
  margin: 0 0 12px;
  font-size: 0.75rem;
  color: #94a3b8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.ruins-map-modal-buff {
  margin: 0 0 8px;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #cbd5e1;
}

.ruins-map-modal-buff:empty {
  display: none;
}

.ruins-map-modal-guild {
  margin: 0;
  font-size: 0.85rem;
  color: #e2e8f0;
}

.ruins-map-modal-hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: #94a3b8;
}

.ruins-map-modal-edit {
  display: grid;
  gap: 14px;
}

.ruins-map-modal-edit[hidden] {
  display: none;
}

.ruins-map-modal-details {
  margin: 0;
  display: grid;
  gap: 10px;
}

.ruins-map-modal-details > div {
  display: grid;
  gap: 2px;
}

.ruins-map-modal-details dt {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #93c5fd;
}

.ruins-map-modal-details dd {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
  color: #f8fafc;
  white-space: pre-wrap;
  word-break: break-word;
}

.ruins-map-modal-edit > label {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
}

.ruins-map-modal-edit select {
  width: 100%;
  border-color: rgba(148, 163, 184, 0.45);
  background: #0f172a;
  color: #f8fafc;
}
.ruins-legend .swatch-pair {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}

.ruins-legend-sep {
  width: 100%;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.ruins-overlay .draft-poly {
  fill: rgba(41, 171, 224, 0.2);
  stroke: #29abe0;
  stroke-width: 0.005;
  stroke-dasharray: 0.01 0.01;
  pointer-events: none;
}

.ruins-overlay .draft-vertex {
  fill: #29abe0;
  stroke: #fff;
  stroke-width: 0.002;
  pointer-events: none;
}

.ruins-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.ruins-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ruins-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.ruins-map-page[data-season-theme] .ruins-btn:not(.ruins-btn-danger) {
  border-color: color-mix(in srgb, var(--season-accent, var(--border)) 40%, var(--border));
}

.ruins-map-page[data-season-theme] .ruins-btn:not(.ruins-btn-danger):hover {
  background: var(--season-soft, #eff6ff);
  color: var(--season-ink, inherit);
}
