.writing-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  backdrop-filter: blur(8px);
  z-index: 1900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.writing-bg.active {
  opacity: 1;
  pointer-events: all;
}

.writing-pad {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  background: var(--bg);
  border: 2px solid var(--primary);
  border-top: 24px solid var(--primary);
  box-shadow: 0 8px 20px var(--primary-shadow);
  z-index: 2000;
  transition: all 0.3s ease;
}

canvas {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  width: 100%;
  height: 50%;
}

#writing-canvas {
  flex: 1;
  height: 50%;
  touch-action: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#glyph-canvas {
  border-bottom: 4px dashed var(--border);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.writing-pad.blank-mode #glyph-canvas,
.writing-pad.blank-mode .writing-translit {
  display: none;
}

.writing-pad.blank-mode #writing-canvas {
  height: 100%;
}

.letter-loader {
  position: fixed;
  display: flex;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-gradient);
  background-color: var(--bg);
  opacity: 0;
  z-index: 2100;
  flex-direction: column;
  align-content: center;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

.letter-loader.visible {
  opacity: 1;
  pointer-events: auto;
}

.writing-pad-header {
  position: absolute;
  top: -28px;
  width: 100%;
  text-align: center;
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-writing-header);
}

.close-button {
  position: absolute;
  top: -34px;
  right: -10px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  font-size: var(--font-size-xll);
  line-height: 0;
  font-weight: bold;
  z-index: 2200;
  background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
  color: white;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.close-button.scale-down {
  transform: scale(0.85);
}

.writing-translit {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  left: 8px;
  width: 50px;
  height: 50px;
  line-height: 0;
  font-size: var(--font-size-lg);
}

.clear-button {
  position: absolute;
  bottom: 4px;
  right: 4px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  font-size: var(--font-size-lg);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.clear-button.scale-down {
  transform: scale(0.85);
}

.undo-button {
  position: absolute;
  bottom: 4px;
  right: 84px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  font-size: var(--font-size-lg);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.undo-button.scale-down {
  transform: scale(0.85);
}

.eraser-button {
  position: absolute;
  bottom: 4px;
  right: 44px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  font-size: var(--font-size-lg);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.eraser-button.scale-down {
  transform: scale(0.85);
}

.nav-prev-button,
.nav-next-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  font-size: var(--font-size-x2l);
  line-height: 0;
  font-weight: 1000;
  background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
  color: white;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-prev-button {
  left: -100px;
}

.nav-next-button {
  right: -100px;
}

.nav-prev-button.scale-down,
.nav-next-button.scale-down {
  transform: translateY(-50%) scale(0.85);
}

.writing-pad.blank-mode .nav-prev-button,
.writing-pad.blank-mode .nav-next-button {
  display: none;
}

.nav-prev-button:disabled,
.nav-next-button:disabled {
  opacity: 0.3;
}

.nav-prev-button:disabled:hover,
.nav-next-button:disabled:hover {
  transform: translateY(-50%);
}

@media (orientation: portrait) {
  .writing-pad {
    width: 75vw;
    height: 75dvh;
  }
}

@media (orientation: landscape) {
  .writing-pad {
    width: 50vw;
    height: 60dvh;
  }
}

@media (orientation: landscape) and (max-width: 1024px) {
  .writing-pad {
    width: 75vw;
    height: 75dvh;
  }
}

@media (max-width: 1024px) {
  .nav-prev-button {
    left: -64px;
  }
  .nav-next-button {
    right: -64px;
  }
}

@media (max-width: 480px) {
  .nav-prev-button {
    left: -50px;
  }
  .nav-next-button {
    right: -50px;
  }
}

@media (max-width: 380px) {
  .nav-prev-button {
    left: -46px;
  }
  .nav-next-button {
    right: -46px;
  }
}
