@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lato:wght@400;700&display=swap');

:root {
  --font-primary: 'Cinzel', serif;
  --font-secondary: 'Lato', sans-serif;
  --color-text-light: #ffffff;
  --color-text-shadow: #000000;
}

#start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 4000;
  text-align: center;
}

#start-screen.hidden {
  display: none;
}

#start-screen h1 {
  font-family: var(--font-primary);
  font-size: 4rem;
}

#start-screen button {
  font-family: var(--font-primary);
  font-size: 1.5rem;
  background: none;
  border: 1px solid #fff;
  color: #fff;
  padding: 1rem 2rem;
  margin: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

#start-screen button:hover {
  background-color: #fff;
  color: #000;
}

#saved-stories-list {
  list-style: none;
  padding: 0;
  max-height: 40vh;
  overflow-y: auto;
}

#saved-stories-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid #555;
}

#saved-stories-list li:hover {
  background-color: #1a1a1a;
}

.story-list-title {
    cursor: pointer;
}

.story-list-actions {
    display: flex;
    gap: 0.5rem;
}

.story-list-actions button {
    font-family: var(--font-secondary);
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid #fff;
    background: none;
    color: #fff;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.story-list-actions button:hover {
    background: #fff;
    color: #000;
}

.story-list-actions .delete-btn {
    border-color: #e74c3c;
    color: #e74c3c;
}

.story-list-actions .delete-btn:hover {
    background: #e74c3c;
    color: #fff;
}

* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-secondary);
  background-color: #000;
  color: var(--color-text-light);
  margin: 0;
  padding: 0;
  overflow: hidden; /* Hide scrollbars */
}

#language-selector {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#language-selector.hidden {
  display: none;
}

#language-selector h2 {
  font-family: var(--font-primary);
  font-size: 2.5rem;
  color: var(--color-text-light);
  text-shadow: 0 0 10px #fff;
  margin-bottom: 2rem;
}

.flags {
  display: flex;
  gap: 1.5rem;
}

.flag-button {
  background: none;
  border: 3px solid transparent;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  transition: all 0.3s ease;
  overflow: hidden;
}

.flag-button:hover {
  border-color: #fff;
  transform: scale(1.1);
}

.flag-button img {
  display: block;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}

#game-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app.hidden {
  display: none;
}

.scene-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: kenburns 20s infinite;
  z-index: 1;
}

.scene-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, transparent 50%, black 100%);
  box-shadow: inset 0 0 10vw 5vw #000; /* Vignette/feathered edge */
  z-index: 2;
}

#game-ui-container {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 4;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.top-bar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.top-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
    pointer-events: none;
}

#game-ui-container > * {
    pointer-events: all; /* But allow clicks on the actual UI elements */
}

#timer, #turn-indicator, #round-counter {
  font-family: var(--font-primary);
  font-size: 1.2rem;
  text-shadow: 2px 2px 4px var(--color-text-shadow);
  background-color: rgba(0,0,0,0.5);
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
}

#progress-container {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#progress-bar {
    flex-grow: 1;
    height: 10px;
    background-color: #555;
    border: 1px solid #fff;
    border-radius: 5px;
}

#progress-bar-fill {
    height: 100%;
    background-color: #2ecc71;
    border-radius: 5px;
    transition: width 0.5s ease-in-out;
}

#subtitle-container {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 2rem;
  z-index: 3;
  color: var(--color-text-light);
  text-shadow: 2px 2px 4px var(--color-text-shadow);
  text-align: center;
}

.story-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

#tts-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #fff;
    padding: 0;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#tts-btn:hover {
    opacity: 1;
}

#story-text {
  font-size: 1.5rem;
  line-height: 1.6;
  margin-bottom: 2rem;
  min-height: 100px; /* Reserve space for typewriter */
  max-height: 10em; /* Limit height to ~6 lines */
  overflow-y: auto; /* Allow scrolling for long text */
  padding-right: 1rem; /* Add some padding for the scrollbar */
}

#options-container {
  margin-top: 2rem;
  visibility: hidden; /* Hidden until typewriter finishes */
  opacity: 0;
  transition: visibility 0s, opacity 0.5s linear;
}

#options-container.visible {
  visibility: visible;
  opacity: 1;
}

#options-container ul {
  list-style: none;
  padding: 0;
}

#options-container li {
  margin-bottom: 1rem;
}

#options-container button,
#custom-option-submit {
  font-family: var(--font-secondary);
  font-size: 1rem;
  background-color: rgba(0, 0, 0, 0.5);
  color: var(--color-text-light);
  border: 1px solid #fff;
  border-radius: 3px;
  padding: 0.75rem 1.5rem;
  width: 100%;
  cursor: pointer;
  transition: background-color 0.3s ease;
  text-align: left;
}

#options-container button:hover,
#custom-option-submit:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

#custom-option-container {
  display: flex;
  gap: 0.5rem;
}

#custom-option-input {
  flex-grow: 1;
  background-color: rgba(0, 0, 0, 0.5);
  border: 1px solid #fff;
  color: #fff;
  padding: 0.75rem;
  font-family: var(--font-secondary);
}

@keyframes kenburns {
  0% {
    transform: scale(1) translate(0, 0);
  }
  50% {
    transform: scale(1.1) translate(-2%, 2%);
  }
  100% {
    transform: scale(1) translate(0, 0);
  }
}

/* Side Panel */
#menu-button {
  background: none;
  border: 1px solid #fff;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 5px;
  text-shadow: 2px 2px 4px var(--color-text-shadow);
  position: relative;
  transition: right 0.3s ease-in-out;
  right: 0;
}

#menu-button.panel-open {
  right: 300px;
}

#side-panel {
  position: fixed;
  top: 0;
  right: 0; /* Aligned to the right */
  width: 300px;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  border-left: 2px solid var(--color-text-light); /* Border on the left */
  z-index: 6000;
  transition: right 0.3s ease-in-out; /* Transition right property */
  padding: 1rem;
  overflow-y: auto;
}

#close-panel-btn {
    display: none;
}

#side-panel.hidden {
  right: -300px; /* Hidden off-screen to the right */
}

#side-panel h3, #side-panel h4 {
  font-family: var(--font-primary);
}

.player-stats {
  border: 1px solid #444;
  border-radius: 5px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.player-stats h4 {
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.player-stats.active-player {
    border-color: #3498db; /* Blue highlight for active player */
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.player-stats.dead {
    opacity: 0.5;
    background-color: #333;
    text-decoration: line-through;
}

.player-class {
    font-style: italic;
    font-size: 0.9rem;
    color: #ccc;
}

.stat-bar-container {
  margin-bottom: 1rem;
  font-family: var(--font-secondary);
}

.stat-bar-container label {
  display: block;
  margin-bottom: 0.25rem;
}

.stat-bar {
  height: 20px;
  background-color: #555;
  border-radius: 3px;
  border: 1px solid #fff;
  width: 100%;
}

.stat-bar > div {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease-in-out;
}

.health-bar { background-color: #2ecc71; }
.mana-bar { background-color: #3498db; }
.risk-bar { background-color: #e74c3c; }

.stat-bar-container span {
  float: right;
  margin-top: -1.4rem;
  font-size: 0.9rem;
  text-shadow: 1px 1px 2px #000;
}


/* Dice Roll Modal */
#riddle-feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 40px;
    border-radius: 10px;
    font-size: 2.5em;
    font-weight: bold;
    color: white;
    z-index: 8000;
    text-shadow: 2px 2px 4px #000000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-in-out, visibility 0.5s ease-in-out;
}

#riddle-feedback.visible {
    opacity: 1;
    visibility: visible;
}

#riddle-feedback.success {
    background-color: rgba(46, 204, 113, 0.8);
}

#riddle-feedback.failure {
    background-color: rgba(231, 76, 60, 0.8);
}

#dice-roll-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: opacity 0.3s ease;
}

#dice-roll-modal.hidden {
  display: none;
}

#dice-roll-modal img {
  max-width: 200px;
  border-radius: 10px;
}

#dice-result {
  font-family: var(--font-primary);
  font-size: 4rem;
  color: #fff;
  text-shadow: 0 0 15px #fff;
  margin-top: 1rem;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#dice-result.visible {
  opacity: 1;
}

/* New Story Dialog */
#new-story-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  text-align: center;
}

#new-story-dialog.hidden {
  display: none;
}

#new-story-dialog h3 {
  font-family: var(--font-primary);
  font-size: 2.5rem;
}

#new-story-dialog input {
  font-family: var(--font-secondary);
  font-size: 1.2rem;
  width: 80%;
  max-width: 500px;
  padding: 0.75rem;
  margin: 1rem 0;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid #fff;
  color: #fff;
}

#new-story-dialog button {
  font-family: var(--font-primary);
  font-size: 1.5rem;
  background: none;
  border: 1px solid #fff;
  color: #fff;
  padding: 1rem 2rem;
  margin-top: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

#new-story-dialog button:hover {
  background-color: #fff;
  color: #000;
}

#time-limit-selection {
  margin: 1.5rem 0;
  text-align: center;
}

#time-limit-selection h4 {
  font-family: var(--font-secondary);
  font-size: 1.2rem;
  font-weight: 400;
  margin: 0 0 0.75rem 0;
}

.time-options {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

.time-options label {
  font-family: var(--font-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

#new-story-dialog input[type="radio"] {
  accent-color: #fff;
  width: 1rem;
  height: 1rem;
}

#player-setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  width: 80%;
  max-width: 500px;
}

.player-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-secondary);
}

#player-names-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.player-name-input {
    font-family: var(--font-secondary);
    font-size: 1.2rem;
    width: 100%;
    padding: 0.75rem;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid #fff;
    color: #fff;
}

#new-story-dialog select {
    background-color: rgba(0,0,0,0.5);
    color: #fff;
    border: 1px solid #fff;
    padding: 0.25rem;
    font-family: var(--font-secondary);
    border-radius: 3px;
}

/* End Screen */
#end-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 7000;
  text-align: center;
}

#end-screen.hidden {
  display: none;
}

#end-screen h2 {
  font-family: var(--font-primary);
  font-size: 3rem;
  color: #e74c3c; /* Red color for emphasis */
}

#end-screen p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

#final-stats {
  font-family: var(--font-secondary);
  font-size: 1.1rem;
}

#end-screen button {
  font-family: var(--font-primary);
  font-size: 1.5rem;
  background: none;
  border: 1px solid #fff;
  color: #fff;
  padding: 1rem 2rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

#end-screen button:hover {
  background-color: #fff;
  color: #000;
}

.end-screen-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

#end-screen #download-pdf-btn {
    background: none;
    border: 1px solid #2ecc71;
    color: #2ecc71;
}

#end-screen #download-pdf-btn:hover {
    background-color: #2ecc71;
    color: #fff;
}

.creator-credits {
    position: absolute;
    bottom: 1rem;
    text-align: center;
    font-family: var(--font-secondary);
    color: #aaa;
    font-size: 0.9rem;
}

.creator-credits p {
    margin: 0 0 0.5rem 0;
}

.coffee-btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid #ffdd00;
    color: #ffdd00;
    text-decoration: none;
    border-radius: 5px;
    transition: all 0.3s ease;
}

.coffee-btn:hover {
    background-color: #ffdd00;
    color: #000;
    text-shadow: none;
}

.logo-large {
    width: 150px;
    margin-bottom: 2rem;
}

#fixed-logo-icon {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 50px;
    height: 50px;
    z-index: 10;
}

#fixed-logo-icon img {
    width: 100%;
    height: 100%;
}

.riddle-title {
    font-family: var(--font-primary);
    font-size: 2rem;
    color: var(--color-text-light);
    text-shadow: 0 0 10px #fff;
    margin-bottom: 1rem;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .scene-background {
        background-size: contain;
        background-repeat: no-repeat;
    }

    #start-screen h1 {
        font-size: 2.5rem;
    }

    #start-screen button {
        font-size: 1.2rem;
        padding: 0.8rem 1.5rem;
    }

    .flags {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
    }

    .flag-button img {
        width: 60px;
        height: 60px;
    }

    #language-selector h2 {
        font-size: 2rem;
    }

    #subtitle-container {
        padding: 1rem;
        bottom: 5rem; /* Make space for progress bar */
    }

    #story-text {
        font-size: 1.2rem;
        line-height: 1.5;
    }

    #options-container {
        margin-top: 1rem;
    }

    #options-container button, #custom-option-submit {
        font-size: 0.9rem;
        padding: 0.75rem;
    }

    #custom-option-container {
        flex-direction: column;
    }

    #game-ui-container {
        flex-direction: column;
        align-items: flex-end;
        gap: 0.5rem;
    }

    .top-bar-wrapper {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        width: 100%;
    }


    #menu-button {
        order: 1;
    }

     #timer, #turn-indicator, #round-counter {
        font-size: 0.9rem;
     }

    #menu-button {
        width: 35px;
        height: 35px;
        font-size: 1.2rem;
    }

    #side-panel {
        width: 80%;
        max-width: 300px;
        border-left: none;
        transition: transform 0.3s ease-in-out;
        transform: translateX(100%);
    }

    #side-panel.hidden {
       transform: translateX(100%);
    }

    #side-panel:not(.hidden) {
        transform: translateX(0);
    }


    #close-panel-btn {
        display: block;
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        background: none;
        border: 1px solid #fff;
        color: #fff;
        font-size: 1.5rem;
        cursor: pointer;
        width: 35px;
        height: 35px;
        border-radius: 5px;
    }

    #menu-button.panel-open {
        transform: translateX(-80vw);
    }

    #new-story-dialog h3 {
        font-size: 2rem;
    }

    #new-story-dialog input, .player-name-input {
        font-size: 1rem;
        width: 90%;
    }

    #end-screen h2 {
        font-size: 2.5rem;
    }

     #end-screen button {
        font-size: 1.2rem;
        padding: 0.8rem 1.2rem;
     }

    .end-screen-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    #fixed-logo-icon {
        top: 0.5rem;
        left: 0.5rem;
        width: 40px;
        height: 40px;
    }

}

.intro-nav-buttons {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}

.intro-nav-buttons button {
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: 1px solid white;
    padding: 10px 20px;
    margin: 0 10px;
    cursor: pointer;
    font-size: 16px;
}

.intro-nav-buttons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
