html,
body {
  overscroll-behavior: none;
}

body {
  background-color: #0d0d0d;
  font-family: serif;
  display: flex;
  justify-content: center;
  height: 100vh;
  margin: 0;
  color: #d4af37;
  height: 100%;
}

.loom-frame {
  background: linear-gradient(145deg, #1a1a1a, #111);
  border: 2px solid #d4af37;
  border-radius: 14px;
  padding: 60px 40px;
  margin: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 450px;
  position: relative;
}

.game-title-container {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

.game-title {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 2px solid #d4af37;
  padding-bottom: 10px;
  flex: 1;
  text-align: center;
}

.home-button {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #d4af37;
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  color: #d4af37;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  text-decoration: none;
  box-sizing: border-box;
  touch-action: manipulation;
}

.home-button svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.home-button:hover {
  background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
  color: #d4af37;
}

.help-button {
  position: absolute;
  right: 0;
  top: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #d4af37;
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  color: #d4af37;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  touch-action: manipulation;
}

.help-button:hover {
  background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.help-button * {
  pointer-events: none;
}

.warp-threads {
  display: flex;
  justify-content: space-between;
  width: 280px;
  min-height: 20px;
}

.thread {
  width: 1px;
  background: linear-gradient(to bottom, #d4af37cc, transparent);
  height: 100%;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 64px);
  grid-template-rows: repeat(4, 64px);
  gap: 14px;
}

.cell {
  width: 64px;
  height: 64px;
  border: 2px solid #444;
  border-radius: 4px;
  background-color: #1c1c1c;
  font-size: 1.4rem;
  font-weight: bold;
  color: #f5deb3;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  user-select: none;
  position: relative;
  box-sizing: border-box;
}

.cell:hover {
  background-color: #2b2b2b;
  transform: scale(1.02);
  transition: all 0.15s ease;
}

.cell.possible-next:hover {
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.25);
}

.banner-message {
  position: fixed;
  bottom: 48px;
  text-align: center;
  left: 0;
  right: 0;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 12px;
}

.banner {
  text-align: center;
  font-size: 1.5rem;
  font-weight: bold;
  color: #d4af37;
  margin: 20px 0;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.word-input {
  width: 200px;
  padding: 11px;
  font-size: 1.2rem;
  border: 1px solid #d4af37;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  background-color: #d4af37;
  color: #000;
  font-weight: bold;
  margin-top: 12px;
  outline: none;
}

.cell.current-word {
  background-color: #e6c757;
  color: #000;
  box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.6);
  border: 2px solid #d4af37;
}

.cell.used:hover {
  background-color: #cfa638;
}

.cell.current {
  background-color: #ffd700 !important;
  color: #000;
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.8) !important;
  animation: pulse 1s ease-in-out infinite;
  border: 2px solid #fff !important;
}

.cell.previous-word {
  background-color: #2a2a2a;
  color: #888;
  opacity: 0.7;
}

.cell.possible-next {
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.15);
}

.submit-button,
.clear-button {
  border: 2px solid #d4af37;
  background-color: transparent;
  color: #d4af37;
  padding: 10px 20px;
  font-size: 1.2rem;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.submit-button:hover,
.clear-button:hover {
  background-color: #d4af37;
  color: #000;
}

.delete-button {
  border: 2px solid #cc6666;
  background-color: transparent;
  color: #cc6666;
  padding: 10px 20px;
  font-size: 1.2rem;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.delete-button:hover {
  background-color: #cc6666;
  color: #000;
}

.delete-button.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #666;
  color: #666;
}

.delete-button.disabled:hover {
  background-color: transparent;
  color: #666;
}

.reset-button {
  border: 2px solid #888;
  background-color: transparent;
  color: #888;
  padding: 8px 16px;
  font-size: 1rem;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.reset-button:hover {
  background-color: #888;
  color: #000;
}

.reset-confirmation {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 2px solid #888;
  border-radius: 8px;
  background-color: #1a1a1a;
}

.confirmation-message {
  color: #f5deb3;
  font-size: 1rem;
  font-weight: bold;
  text-align: center;
}

.confirmation-buttons {
  display: flex;
  gap: 12px;
}

.confirm-button {
  border: 2px solid #cc4444;
  background-color: transparent;
  color: #cc4444;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.confirm-button:hover {
  background-color: #cc4444;
  color: #fff;
}

.cancel-button {
  border: 2px solid #888;
  background-color: transparent;
  color: #888;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cancel-button:hover {
  background-color: #888;
  color: #000;
}

.current-input {
  color: #d4af37;
  border-bottom: 2px solid #cfa638;
  font-size: 1.4rem;
  font-weight: bold;
  margin: 12px 4px;
}

.letter-input-area {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 16px;
  user-select: none;
  min-height: 48px;
}

.input-text-container {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  width: auto;
  height: 36px;
  border-bottom: 2px solid #d4af37;
  padding: 4px 16px;
  background: rgba(212, 175, 55, 0.1);
  border-radius: 4px 4px 0 0;
  transition: width 0.2s ease;
}

.input-text {
  font-size: 1.6rem;
  font-weight: bold;
  color: #d4af37;
  letter-spacing: 2px;
  line-height: 1;
  white-space: nowrap;
}

.blinking-cursor {
  font-size: 1.6rem;
  font-weight: bold;
  color: #d4af37;
  animation: blink 1s infinite;
  margin-left: 2px;
  line-height: 1;
}

.current-typing-word .blinking-cursor {
  font-size: 20px;
  margin-left: 1px;
}

@keyframes blink {
  0%,
  50% {
    opacity: 1;
  }
  51%,
  100% {
    opacity: 0;
  }
}

.input-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0;
}

.letter-view-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.backspace-button {
  width: 44px;
  height: 36px;
  border: 1px solid #888;
  border-radius: 4px;
  background-color: transparent;
  font-size: 1.4rem;
  font-weight: bold;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  box-sizing: border-box;
}

.backspace-button:hover {
  background-color: #2b2b2b;
  border-color: #aaa;
  color: #aaa;
}

.backspace-button.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.backspace-button.disabled:hover {
  background-color: transparent;
  border-color: #888;
  color: #888;
}

.divider {
  width: 100%;
  height: 2px;
  background: linear-gradient(
    to right,
    transparent 0%,
    #d4af37 30%,
    #d4af37 70%,
    transparent 100%
  );
}

.grid-wrapper {
  margin: 8px 0;
}

.game-board-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flash-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #2a2a2a;
  border: 2px solid #d4af37;
  border-radius: 8px;
  padding: 20px 40px;
  color: #f5deb3;
  font-size: 1.1rem;
  font-weight: bold;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  z-index: 100;
  animation: flashFadeIn 0.3s ease-out;
  min-width: 200px;
  white-space: nowrap;
}

@keyframes flashFadeIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.flip-vertical {
  transform: scaleY(-1);
}

.button-container {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.primary-buttons {
  display: flex;
  gap: 8px;
}

.words-display {
  margin: 16px 12px;
  text-align: center;
  min-height: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.completed-word {
  font-size: 20px;
  font-weight: bold;
  color: #d4af37;
  opacity: 0.8;
}

.current-word-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.current-typing-word {
  font-size: 20px;
  font-weight: bold;
  color: #d4af37;
  border-bottom: 3px solid #d4af37;
  padding-bottom: 4px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  min-width: 40px;
  user-select: none;
}

.clear-word-button {
  width: 20px;
  height: 20px;
  border: 1px solid #cc6666;
  border-radius: 50%;
  background-color: transparent;
  color: #cc6666;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
  padding: 0;
}

.clear-word-button:hover {
  background-color: #cc6666;
  color: #000;
  transform: scale(1.1);
}

.invalid-flash-word {
  animation: wordFlash 0.3s ease-in-out;
}

@keyframes wordFlash {
  0% {
    color: #d4af37;
  }
  50% {
    color: #cc3333;
  }
  100% {
    color: #d4af37;
  }
}

.solve-message {
  font-size: 20px;
  color: #f5deb3;
  opacity: 0.8;
}

.try-to-solve-message {
  margin: 20px 12px 12px 12px;
  font-size: 20px;
  text-align: center;
  user-select: none;
}

@media (max-width: 768px) {
  .loom-frame {
    width: calc(100vw - 16px);
    height: 75vh;
    height: 75dvh;
    padding: 8px;
    margin: 8px;
    max-width: none;
  }

  .game-title {
    font-size: 2rem;
    letter-spacing: 0.5px;
  }

  .grid-container {
    grid-template-columns: repeat(4, calc((100vw - 120px) / 4));
    grid-template-rows: repeat(4, calc((100vw - 120px) / 4));
    gap: 10px;
  }

  .cell {
    width: calc((100vw - 120px) / 4);
    height: calc((100vw - 120px) / 4);
    font-size: 1.4rem;
  }

  .word-input {
    width: 160px;
    font-size: 1rem;
  }

  .submit-button,
  .clear-button,
  .delete-button {
    font-size: 1rem;
    padding: 8px 16px;
  }

  .button-container {
    gap: 8px;
  }

  .reset-button {
    font-size: 0.9rem;
    padding: 6px 12px;
  }

  .letter-input-area {
    margin-top: 4px;
  }

  .input-text-container {
    min-width: 50px;
    height: 32px;
    padding: 4px 12px;
  }

  .input-text,
  .blinking-cursor {
    font-size: 1.3rem;
  }

  .backspace-button {
    width: 36px;
    height: 32px;
    font-size: 1.2rem;
  }

  .button-container {
    margin-top: 20px;
    gap: 12px;
  }

  .reset-confirmation {
    padding: 12px;
    gap: 8px;
  }

  .confirmation-message {
    font-size: 0.9rem;
  }

  .confirmation-buttons {
    gap: 8px;
  }

  .confirm-button,
  .cancel-button {
    font-size: 0.8rem;
    padding: 6px 12px;
  }

  .words-display {
    margin: 12px 8px;
    gap: 6px;
  }

  .completed-word,
  .current-typing-word,
  .solve-message {
    font-size: 16px;
  }

  .current-typing-word {
    min-width: 32px;
    padding-bottom: 3px;
  }

  .clear-word-button {
    width: 18px;
    height: 18px;
    font-size: 12px;
  }

  .current-word-container {
    gap: 6px;
  }

  .try-to-solve-message {
    font-size: 16px;
    margin: 16px 8px 8px 8px;
  }

}

@media (max-width: 480px) {
  .loom-frame {
    width: calc(100vw - 12px);
    height: 80vh;
    height: 80dvh;
    padding: 6px;
    margin: 6px;
    max-width: none;
  }

  .game-title {
    font-size: 1.6rem;
    letter-spacing: 0px;
    padding-bottom: 8px;
  }

  .grid-container {
    grid-template-columns: repeat(4, calc((100vw - 100px) / 4));
    grid-template-rows: repeat(4, calc((100vw - 100px) / 4));
    gap: 8px;
  }

  .cell {
    width: calc((100vw - 100px) / 4);
    height: calc((100vw - 100px) / 4);
    font-size: 1.5rem;
  }

  .home-button,
  .help-button {
    width: 28px;
    height: 28px;
  }

  .help-button {
    font-size: 0.8rem;
  }

  .home-button svg {
    width: 14px;
    height: 14px;
  }

  .word-input {
    width: 120px;
    font-size: 0.9rem;
  }

  .submit-button,
  .clear-button,
  .delete-button {
    font-size: 1rem;
    padding: 10px 16px;
    min-height: 44px;
  }

  .reset-button {
    font-size: 0.8rem;
    padding: 5px 10px;
  }

  .input-text-container {
    min-width: 40px;
    height: 28px;
    padding: 3px 10px;
  }

  .input-text,
  .blinking-cursor {
    font-size: 1.1rem;
  }

  .backspace-button {
    width: 32px;
    height: 28px;
    font-size: 1rem;
  }

  .reset-confirmation {
    padding: 10px;
    gap: 6px;
  }

  .confirmation-message {
    font-size: 0.8rem;
  }

  .confirmation-buttons {
    gap: 6px;
  }

  .confirm-button,
  .cancel-button {
    font-size: 0.7rem;
    padding: 5px 10px;
  }
}

/* Very small mobile devices */
@media (max-width: 360px) {
  .grid-container {
    grid-template-columns: repeat(4, calc((100vw - 80px) / 4));
    grid-template-rows: repeat(4, calc((100vw - 80px) / 4));
    gap: 6px;
  }

  .cell {
    width: calc((100vw - 80px) / 4);
    height: calc((100vw - 80px) / 4);
    font-size: 1.3rem;
  }

  .loom-frame {
    padding: 4px;
    margin: 2px;
    width: calc(100vw - 8px);
    height: 85vh;
    height: 85dvh;
  }

  .submit-button,
  .clear-button,
  .delete-button {
    font-size: 0.9rem;
    padding: 8px 14px;
    min-height: 40px;
  }
}

/* Thread animation and texture effects */
@keyframes threadWeave {
  0%,
  100% {
    opacity: 0.9;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes threadShimmer {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.1);
  }
  100% {
    filter: brightness(1);
  }
}

.grid-wrapper svg {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.grid-wrapper svg path {
  animation: threadWeave 3s ease-in-out infinite;
}

.grid-wrapper svg path:nth-child(2) {
  animation-delay: 0.5s;
}

.grid-wrapper svg path:nth-child(3) {
  animation-delay: 1s;
  animation: threadShimmer 4s ease-in-out infinite;
}

.grid-wrapper svg path:nth-child(4) {
  animation-delay: 1.5s;
}

/* Add texture to the frame */
.loom-frame::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(212, 175, 55, 0.03) 10px,
    rgba(212, 175, 55, 0.03) 20px
  );
  pointer-events: none;
  border-radius: 14px;
}

/* Enhanced thread visual on hover */
.grid-container:hover + svg path {
  filter: brightness(1.2);
  transition: filter 0.3s ease;
}

/* Pulse animation for current letter */
@keyframes pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 215, 0, 1);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
  }
}

/* Position indicators removed for cleaner look */

/* Red flash animation for invalid letter input */
@keyframes invalidFlash {
  0% {
    background-color: #1c1c1c;
  }
  50% {
    background-color: #cc3333;
  }
  100% {
    background-color: #1c1c1c;
  }
}

.letter-input-area.invalid-flash .input-text-container {
  animation: invalidFlash 0.3s ease-in-out;
}

/* Modal styles */
dialog {
  background: linear-gradient(145deg, #1a1a1a, #111);
  border: 2px solid #d4af37;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  max-width: 500px;
  width: 90vw;
  max-height: 700px;
  overflow: hidden;
  font-family: serif;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(2px);
}

.wordloom-dialog {
  animation: dialogFadeIn 0.3s ease-out;
}

@keyframes dialogFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.dialog-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: #d4af37;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.dialog-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: #d4af37;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dialog-close-button {
  background: none;
  border: none;
  color: #d4af37;
  font-size: 1.5rem;
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.dialog-close-button:hover {
  background-color: rgba(212, 175, 55, 0.1);
}

.dialog-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  line-height: 1.4;
}

.objective {
  margin: 0 0 16px 0;
  font-size: 1rem;
  color: #f5deb3;
  text-align: center;
  padding: 8px;
  background: rgba(212, 175, 55, 0.1);
  border-radius: 4px;
}

.demo-container {
  margin: 0 0 16px 0;
  text-align: center;
  padding: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  border: 1px solid #333;
}

.demo-video {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid #444;
  max-height: 280px;
  object-fit: contain;
  width: 100%;
}

.rules-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule-item {
  font-size: 0.9rem;
  color: #ccc;
  line-height: 1.3;
}

.rule-item strong {
  color: #d4af37;
  font-weight: 600;
}

.dialog-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid #333;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.dialog-ok-button {
  background: linear-gradient(145deg, #d4af37, #b8941f);
  border: none;
  color: #1a1a1a;
  padding: 8px 20px;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.dialog-ok-button:hover {
  background: linear-gradient(145deg, #e6c347, #d4af37);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Mobile responsiveness for dialog */
@media (max-width: 768px) {
  dialog {
    max-width: 95vw;
    max-height: 90vh;
  }

  .dialog-header,
  .dialog-body,
  .dialog-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .dialog-title {
    font-size: 1.1rem;
  }

  .help-button {
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }

  .demo-video {
    max-height: 200px;
  }

  .objective {
    font-size: 0.9rem;
  }

  .rule-item {
    font-size: 0.85rem;
  }
}
