html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: sans-serif;
    background: #000;
    color: #fff;
}

.hidden { visibility: hidden; }
.nodisplay { display: none; }
.black { color: #000; }
.mostly-hidden { opacity: 0.1; }

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    min-height: 56px;
    background: #111;
    padding: 4px 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    flex-wrap: nowrap;
    gap: 12px;
    z-index: 10;
}

.topbar p {
    margin: 2px 0;
}

.topbar-left,
.topbar-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}

.topbar-center {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
}

.low-charge {
    color: yellow;
}

.no-path {
    color: red;
}

#viewport {
    position: absolute;
    top: auto;
    inset: 56px 0 100px 0; /* top = topbar min height, bottom = inventory */
    bottom: 100px; /* height of inventory */
    left: 0;
    right: 0;
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;
    user-select: none;
    background-color: #000;
    z-index: 1;
}

#inventory-canvas {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    display: block;
    touch-action: none;
    user-select: none;
    background-color: #111;
    border-top: 1px solid #333;
    z-index: 5;
}

.tile {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(2.8vw);
    background-color: #222;
    color: #eee;
    border: 1px solid #333;
    -webkit-tap-highlight-color: transparent;
}

.floor { background-color: #222; }
.wall { background-color: #666; position: relative; }
.dalek { background-color: crimson; color: white; font-weight: bold; }
.forcewall { background-color: #06F; }

.highlight i {
    position: absolute;
    top: 2px;
    right: 2px;
    color: #ff0;
    font-size: 0.7em;
}

.overlay h2 {
    color: #000;
}

.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 32px;
    z-index: 9999;
    cursor: pointer;
    text-align: center;
}

.overlay.active {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1000;
}

.overlay-grid {
    display: grid;
    grid-template-columns: repeat(var(--gridSize), minmax(20px, 1fr));
    grid-auto-rows: minmax(20px, 1fr);
    aspect-ratio: 1 / 1;
    /*width: min(95vmin, 95vh);*/
    max-width: 95vmin;
    max-height: 95vmin;
    gap: 0;
    overflow: auto;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

.overlay-grid .tile {
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    overflow: hidden;
}

/* wormhole bits */
@keyframes shimmer {
    0% {
        background-position: 0% 50%;
        filter: brightness(1);
    }
    50% {
        background-position: 100% 50%;
        filter: brightness(1.4);
    }
    100% {
        background-position: 0% 50%;
        filter: brightness(1);
    }
}

.wormhole {
    position: relative;
    background: radial-gradient(circle, #00f4ff 0%, #004080 60%, #000020 100%);
    background-size: 200% 200%;
    animation: shimmer 2s infinite ease-in-out;
    border: 2px solid #66ccff;
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.4), inset 0 0 8px rgba(0, 128, 255, 0.5);
    border-radius: 35% / 100%;
    -webkit-mask-image: radial-gradient(ellipse 35% 100% at center, black 100%, transparent 100%);
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
    mask-image: radial-gradient(ellipse 35% 100% at center, black 100%, transparent 100%);
    mask-repeat: no-repeat;
    mask-size: 100% 100%;
}

.modal {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.canvas-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
}

canvas#viewport {
    display: block;
    margin: 0 auto;
}

.description {
    color: #000;
}

#item-description-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    pointer-events: auto;
    touch-action: manipulation;
}

#item-description-modal .modal {
    background: white;
    padding: 1rem;
    border-radius: 0.5rem;
    pointer-events: auto;
    touch-action: manipulation;
    position: relative;
}

#item-description-modal .modal p {
    display: flex;
    justify-content: center;
    gap: 20px;
}

#item-description-modal .modal p button {
    margin: 0;
}

#close-desc {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    width: 44px;
    height: 44px;
    pointer-events: auto;
    touch-action: manipulation;
    z-index: 10000;
}

#item-description-modal.nodisplay {
    display: none !important;
}

#item-description-modal * {
    color: black !important;
}

#destabilizer-display {
    position: fixed;
    bottom: 100px;
    left: 0;
    right: 0;
    z-index: 6; /* higher than #inventory-canvas (z-index: 5) */
}

.destabilizer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background-color: #222;
    color: white;
    font-size: 16px;
    height: 40px;
}

#destab-activate {
    padding: 4px 10px;
    font-size: 14px;
    background-color: #444;
    color: white;
    border: 1px solid #888;
    cursor: pointer;
}

#destab-canvas {
    display: block;
    position: relative;
    box-sizing: border-box;
    touch-action: manipulation;
    user-select: none;
}

#destab-activate:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.status-icons {
    display: grid;
    grid-template-columns: repeat(7, 24px);
    grid-template-rows: repeat(2, 24px);
    gap: 0 0px;
    align-items: center;
    height: 48px;
}

.status-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    transition: opacity 0.2s;
}

.status-icon.mostly-hidden {
    opacity: 0.1;
}

#message-display {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 160px;
    text-align: left;
    z-index: 7;
    pointer-events: none;
}

.message-content {
    display: inline-block;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 0px 0px;
    font-size: 18px;
    width: 100%;
    margin: 0 auto;
    line-height: 1.0;
    pointer-events: auto;
}

.ring-container {
    width: 48px;
    height: 48px;
    position: relative;
}

.ring-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 6px #0ff);
    animation: pulse-glow 6s infinite ease-in-out;
}

.ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring circle {
    fill: none;
    stroke-width: 10;
    r: 45;
    cx: 50;
    cy: 50;
}

.ring .bg {
    stroke: #111;
}

/* stroke-dasharray is 2 * π * r = 2 * 3.14159 * 45 ≈ 282.74 */
.ring .fg {
    stroke: hsl(160, 100%, 55%);
    stroke-linecap: round;
    stroke-dasharray: 282.74;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
}

.ring-label {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    line-height: 48px;
    text-align: center;
    font-size: 12px;
    pointer-events: none;
    color: white;
    text-shadow: 0 0 2px #0ff;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

#circle-label {
    white-space: nowrap;
    font-size: 14px;
}

#stability-crack {
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 48px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
}

#stability-crack.visible {
    opacity: 1;
}

#stability-wrapper-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stability-label {
    color: white;
    font-size: 14px;
}

@keyframes pulse-glow {
    0%, 100% {
        filter: drop-shadow(0 0 4px #0ff);
    }
    50% {
        filter: drop-shadow(0 0 10px #0ff);
    }
}

#destab-charge-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.destab-label {
    color: white;
    font-size: 14px;
}

#destab-charge-container {
    position: relative;
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 0 6px #0ff);
    animation: pulse-glow 6s infinite ease-in-out;
}

#destab-charge-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

#destab-charge-ring circle {
    fill: none;
    stroke-width: 10;
    r: 45;
    cx: 50;
    cy: 50;
}

#destab-charge-ring .bg {
    stroke: #111;
}

#destab-charge-ring .fg {
    stroke: hsl(160, 100%, 55%);
    stroke-linecap: round;
    stroke-dasharray: 282.74;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.4s ease, stroke 0.3s ease;
}

#destab-charge-label {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    line-height: 32px;
    text-align: center;
    font-size: 11px;
    color: white;
    pointer-events: none;
    text-shadow: 0 0 2px #0ff;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

@keyframes flicker {
    0%   { opacity: 1; filter: brightness(1); }
    10%  { opacity: 0.6; filter: brightness(1.4); }
    20%  { opacity: 0.4; filter: brightness(0.8); }
    30%  { opacity: 0.7; filter: brightness(1.1); }
    40%  { opacity: 0.3; filter: brightness(1.3); }
    50%  { opacity: 0.6; filter: brightness(1); }
    60%  { opacity: 0.8; filter: brightness(1.2); }
    70%  { opacity: 0.5; filter: brightness(0.9); }
    80%  { opacity: 0.9; filter: brightness(1.3); }
    90%  { opacity: 0.6; filter: brightness(0.7); }
    100% { opacity: 1; filter: brightness(1); }
}

.discharged {
    animation: flicker 0.8s infinite;
}

.pulse-yellow {
    outline: 3px solid rgba(255, 255, 0, 0.8);
    outline-offset: -3px;
    animation: pulse-yellow-outline 1s infinite;
}

@keyframes pulse-yellow-outline {
    0%   { outline-color: rgba(255, 255, 0, 0); }
    50%  { outline-color: rgba(255, 255, 0, 0.9); }
    100% { outline-color: rgba(255, 255, 0, 0); }
}

.topbar-shards {
    position: relative;
    width: 72px;
    height: 48px;
}

.shard-icon {
    position: absolute;
    width: 24px;
    height: 24px;
    object-fit: contain;
    transition: opacity 0.2s ease;
}

/* Row 1 (player shards) */
.topbar-shards img:nth-child(1) {
    top: 0;
    left: 0px;
    z-index: 3;
}
.topbar-shards img:nth-child(2) {
    top: 0;
    left: 16px;
    z-index: 2;
}
.topbar-shards img:nth-child(3) {
    top: 0;
    left: 32px;
    z-index: 1;
}

/* Row 2 (opponent shards) */
.topbar-shards img:nth-child(4) {
    top: 24px;
    left: 0px;
    z-index: 3;
}
.topbar-shards img:nth-child(5) {
    top: 24px;
    left: 16px;
    z-index: 2;
}
.topbar-shards img:nth-child(6) {
    top: 24px;
    left: 32px;
    z-index: 1;
}

.shard-icon.hidden {
    opacity: 0;
    visibility: hidden;
}

#progress-container {
    margin-top: 1em;
    width: 80%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

#progress-bar {
    width: 100%;
    height: 24px;
    background: #222;
    border: 2px solid #888;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 5px #0ff;
    position: relative;
}

#progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #0ff, #08f);
    box-shadow: inset 0 0 8px #0ff;
    transition: width 0.2s ease;
}

#progress-text {
    margin-top: 0.5em;
    color: #0ff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1em;
    text-shadow: 0 0 3px #0ff;
}

.sizeit {
    font-size: 18px;
}

.paragraph-text {
    font-size: 18px;
    padding: 0 0 0 0;
}

.rules-slide {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.rules-slide.active {
    display: flex;
}

#rules-modal-content {
    position: relative;
    padding-bottom: 3em;
}

.story-buttons {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem; /* space between buttons */
}

.story-buttons button {
  font-size: 1rem;
  font-weight: bold; /* matches nextbutton bold style */
  color: #000;
  cursor: pointer;
  margin: 0;
}

#rules-modal .modal {
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-sizing: border-box;
    padding: 1rem 1rem 4rem 1rem;
    max-width: 95vw;
    width: 100%;
    margin: 0 auto;
}

