body {
    font-family: 'Nunito', sans-serif;
    background-color: #3d405b;
    color: #f4f1de;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
}

#player-count {
    position: fixed;
    top: 1rem;
    left: 1rem;
    background-color: rgba(44, 47, 72, 0.8);
    color: #f4f1de;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    z-index: 1000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid #4a4e69;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    font-weight: 700;
}

#app {
    text-align: center;
    background-color: #2c2f48;
    padding: 2rem 3rem;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 700px;
    border: 1px solid #4a4e69;
}

#main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

h1 {
    color: #f2cc8f;
    font-weight: 700;
    font-size: 2.5rem;
    margin-top: 0;
    margin-bottom: 0;
}

#like-btn {
    background-color: #4a4e69;
    color: #f4f1de;
    border: 1px solid #8d99ae;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

#like-btn:hover:not(:disabled) {
    background-color: #f2cc8f;
    color: #2c2f48;
    border-color: #f2cc8f;
    transform: translateY(-2px);
}

#like-btn.liked {
    background-color: #81b29a;
    color: #2c2f48;
    border-color: #81b29a;
    cursor: default;
}

#selection-prompt {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: #e0e1dd;
    min-height: 1.3em;
}

#unlock-hint {
    margin-bottom: 2rem;
    font-size: 0.9rem;
    color: #f2cc8f;
    font-style: italic;
}

p {
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
    color: #e0e1dd;
}

#character-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    min-height: 200px; /* Ensure grid has height even when empty */
    align-content: start;
}

.character-card {
    background-color: #3d405b;
    border: 3px solid #4a4e69;
    border-radius: 15px;
    padding: 1rem;
    cursor: pointer;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    overflow: hidden;
}

.character-card:hover {
    transform: translateY(-8px);
    border-color: #f2cc8f;
}

.character-card.selected {
    border-color: #81b29a;
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 0 20px rgba(129, 178, 154, 0.5);
}

.new-tag {
    display: none;
}

.character-card img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 1rem;
    background-color: #2c2f48;
}

.character-card h3 {
    margin: 0;
    color: #f4f1de;
    font-size: 1.2rem;
    font-weight: 700;
}

#start-btn {
    background-color: #e07a5f;
    color: #fff;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s, transform 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#start-btn:hover:not(:disabled) {
    background-color: #d66447;
    transform: translateY(-2px);
}

#start-btn:disabled {
    background-color: #8d99ae;
    cursor: not-allowed;
    opacity: 0.6;
}

/* General utility */
.hidden {
    display: none !important;
}

/* Chat Screen Styles */
#chat-screen {
    width: 100%;
    max-width: 800px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    background-color: #2c2f48;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid #4a4e69;
    overflow: hidden; /* To keep border radius on children */
}

#chat-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: #3d405b;
    border-bottom: 1px solid #4a4e69;
}

#back-btn {
    background: none;
    border: 1px solid #f2cc8f;
    color: #f2cc8f;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-family: 'Nunito', sans-serif;
    transition: background-color 0.2s, color 0.2s;
    margin-right: 1.5rem;
}

#back-btn:hover {
    background-color: #f2cc8f;
    color: #3d405b;
}

#chat-title {
    color: #f4f1de;
    font-size: 1.5rem;
    margin: 0;
    font-weight: 700;
}

#chat-messages {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    max-width: 75%;
}

.chat-message .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.message-bubble {
    background-color: #3d405b;
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    color: #e0e1dd;
    line-height: 1.5;
    word-break: break-word;
}

.chat-message.right {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.center {
    align-self: center;
}

.chat-message.right .message-bubble {
    background-color: #81b29a;
    color: #1a2620;
}

.chat-message.center .message-bubble {
    background-color: #f2cc8f;
    color: #3d405b;
}

.message-bubble.image-message {
    padding: 0;
    background-color: transparent;
}

.message-bubble.image-message img {
    max-width: 200px;
    border-radius: 18px;
    display: block;
}

.chat-message.right .message-bubble.image-message {
    background-color: transparent;
}

#typing-indicator {
    padding: 1rem 1.5rem;
    font-style: italic;
    color: #a0a3b6;
    height: 48px; /* reserve space to prevent layout shift */
    box-sizing: border-box;
}

#typing-indicator .dot {
  animation: blink 1.4s infinite both;
}

#typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}

#typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0% { opacity: 0.2; }
  20% { opacity: 1; }
  100% { opacity: 0.2; }
}

.narrator-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #f2cc8f;
    font-size: 0.9rem;
}

/* The switch - a box around the slider */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #4a4e69;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
}

input:checked + .slider {
  background-color: #81b29a;
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Multiplayer Chat Styles */
#multiplayer-chat {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 320px;
    height: 450px;
    background-color: #2c2f48;
    border-radius: 15px;
    border: 1px solid #4a4e69;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    z-index: 1001; /* Above player count */
    overflow: hidden;
    transition: transform 0.3s ease-in-out;
}

#chat-header-mp {
    background-color: #3d405b;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #4a4e69;
    cursor: pointer;
}

#chat-header-mp h3 {
    margin: 0;
    color: #f2cc8f;
    font-size: 1.1rem;
    text-align: center;
}

#chat-messages-mp {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mp-chat-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 90%;
}

.mp-chat-message .author {
    font-size: 0.8rem;
    color: #f2cc8f;
    margin-bottom: 0.25rem;
    font-weight: bold;
    padding-left: 0.2rem;
}

.mp-chat-message .content {
    background-color: #3d405b;
    padding: 0.5rem 0.8rem;
    border-radius: 12px;
    color: #e0e1dd;
    line-height: 1.4;
    word-break: break-word;
}

.mp-chat-message.own-message {
    align-self: flex-end;
    align-items: flex-end;
}

.mp-chat-message.own-message .author {
    color: #81b29a;
}

.mp-chat-message.own-message .content {
    background-color: #81b29a;
    color: #1a2620;
}

.mp-chat-message.system-message {
    align-self: center;
    color: #a0a3b6;
    font-style: italic;
    font-size: 0.9rem;
    max-width: 100%;
}

#chat-input-container-mp {
    display: flex;
    padding: 0.75rem;
    border-top: 1px solid #4a4e69;
    gap: 0.5rem;
    background-color: #3d405b;
}

#chat-input-mp {
    flex-grow: 1;
    background-color: #2c2f48;
    border: 1px solid #4a4e69;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    color: #f4f1de;
    font-family: 'Nunito', sans-serif;
    font-size: 1rem;
}

#chat-input-mp:focus {
    outline: none;
    border-color: #f2cc8f;
}

#chat-send-btn-mp {
    background-color: #e07a5f;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
}

#chat-send-btn-mp:hover {
    background-color: #d66447;
}