:root {
    --bg-color: #000000;
    --text-color: #f8fafc;
    --glow-color: rgba(59, 130, 246, 0.15);
    --paper-bg: #ffffff;
    --paper-text: #222222;
    --paper-line: #d0d0d0;
    --body-grad-a: #667eea;
    --body-grad-b: #764ba2;
    --body-grad-c: #5a4a8a;
    --key-bg-a: #1a1a1a;
    --key-bg-b: #111111;
    --key-border: #333333;
    --key-text: #f5f5f5;
    --key-active-bg: #1e3a5f;
    --key-active-border: #3b82f6;
    --key-active-shadow: rgba(59, 130, 246, 0.55);
    --input-bg: rgba(255,255,255,0.07);
    --input-border: rgba(255,255,255,0.2);
    --input-color: #f5f5f5;
    --input-placeholder: rgba(255,255,255,0.55);
}

body.light-theme {
    --bg-color: #ffffff;
    --text-color: #111111;
    --glow-color: rgba(59, 130, 246, 0.10);
    --body-grad-a: #7c85d8;
    --body-grad-b: #8b5fad;
    --body-grad-c: #6a56a2;
    --key-bg-a: #f5f5f5;
    --key-bg-b: #e0e0e0;
    --key-border: #c8c8c8;
    --key-text: #222222;
    --key-active-bg: #dbeafe;
    --key-active-border: #3b82f6;
    --key-active-shadow: rgba(59, 130, 246, 0.5);
    --input-bg: rgba(0,0,0,0.07);
    --input-border: rgba(0,0,0,0.18);
    --input-color: #f5f5f5;
    --input-placeholder: rgba(255,255,255,0.65);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    font-family: 'Courier Prime', 'Courier New', monospace;
    padding: 20px;
    position: relative;
    transition: background-color 0.4s ease, color 0.4s ease;
}

body::before,
body::after {
    content: "";
    position: fixed;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: var(--glow-color);
    filter: blur(90px);
    z-index: 0;
    pointer-events: none;
    animation: floatingGlow 8s ease-in-out infinite;
}

body::before { top: -120px; left: -120px; }
body::after  { bottom: -120px; right: -120px; animation-delay: 4s; }

@keyframes floatingGlow {
    0%,100% { transform: translateY(0); }
    50%      { transform: translateY(28px); }
}

.theme-toggle {
    position: fixed;
    top: 20px; right: 20px;
    font-size: 30px;
    cursor: pointer;
    z-index: 10;
    transition: transform 0.3s ease;
    user-select: none;
}
.theme-toggle:hover { transform: scale(1.15) rotate(20deg); }

.typewriter-machine {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(96vw, 1200px);
}

.paper-sheet {
    width: 100%;
    min-height: 500px;
    max-height: 1120px;
    padding: 30px;
    background: linear-gradient(rgba(255,255,255,.96),rgba(250,250,250,.98)),
    url("https://www.transparenttextures.com/patterns/paper-fibers.png");
    background-size: cover;
    box-sizing: border-box;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 0 32px rgba(59,130,246,0.18);
    font-family: 'Courier Prime', monospace;
    font-size: clamp(1.2rem, 1.8vw, 1.9rem);
    line-height: 32px;
    letter-spacing: 0.04em;
    position: relative;
    transition: background 0.4s ease, color 0.4s ease;
    text-align: left;
    animation: pageAppear .4s ease;
    color: #000000;
}

.paper-sheet span {
    color: #000000;
}

@keyframes pageAppear{
    from{
    transform:translateX(40px);
    opacity:0;
    }
    to{
    transform:none;
    opacity:1;
    }
}

.paper-sheet::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 31px,
        var(--paper-line) 31px,
        var(--paper-line) 32px
    );
    pointer-events: none;
    border-radius: 8px 8px 0 0;
}

.typewriterText {
    display: inline;
    position: relative;
    z-index: 2;
    white-space: pre-wrap;
}

.cursor-paper {
    display: inline-block;
    background-color: var(--paper-text);
    width: 3px;
    height: 1.6ex;
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: blink-paper 1s infinite;
    position: relative;
    z-index: 2;
    transition: background-color 0.4s;
}

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

.typewriter-body {
    width: 100%;
    background: linear-gradient(135deg, var(--body-grad-a) 0%, var(--body-grad-b) 50%, var(--body-grad-c) 100%);
    padding: 44px 36px 40px;
    border-radius: 0 0 18px 18px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.45), inset 0 2px 5px rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.input-area { display: flex; flex-direction: column; gap: 10px; }

#userInput {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    background-color: var(--input-bg);
    color: var(--input-color);
    font-family: 'Courier Prime', monospace;
    transition: border-color 0.25s, background-color 0.25s, box-shadow 0.25s;
}
#userInput:focus {
    outline: none;
    border-color: rgba(59,130,246,0.55);
    background-color: rgba(255,255,255,0.12);
    box-shadow: 0 0 10px rgba(59,130,246,0.22);
}
#userInput::placeholder { color: var(--input-placeholder); }

.keyboard {
    display: flex; flex-direction: column;
    align-items: center; gap: 13px; width: 100%;
}

.keyboard-row {
    display: flex; gap: 11px;
    justify-content: center; flex-wrap: wrap;
}

.key {
    width: 54px; height: 54px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--key-bg-a), var(--key-bg-b));
    border: 2px solid var(--key-border);
    box-shadow:
        0 5px 10px rgba(0,0,0,0.32),
        inset 0 1px 3px rgba(255,255,255,0.8),
        inset 0 -2px 3px rgba(0,0,0,0.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    color: var(--key-text);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
    position: relative;
    font-family: Arial, sans-serif;
    text-transform: uppercase;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.key:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.38), inset 0 1px 3px rgba(255,255,255,0.8);
}

.key.pressed,
.key:active {
    transform: translateY(2px);
    background: linear-gradient(145deg, var(--key-active-bg), #bfdbfe);
    border-color: var(--key-active-border);
    box-shadow:
        0 2px 6px rgba(0,0,0,0.28),
        0 0 10px var(--key-active-shadow),
        inset 0 1px 2px rgba(255,255,255,0.6);
}

#row-numbers .key {
    width: 70px;
    border-radius: 14px;
    font-size: 13px;
}

.key.space {
    width: 420px;
    border-radius: 22px;
    font-size: 11px;
    letter-spacing: 2px;
}

.key.backspace {
    width: 90px;
    border-radius: 10px;
    font-size: 11px;
}

.key.enter-key {
    width: 90px;
    border-radius: 10px;
    font-size: 11px;
}

@media (max-width: 768px) {
    body { padding: 10px; }
    .paper-sheet { padding: 18px; min-height: 140px; font-size: 1.1rem; }
    .typewriter-body { padding: 18px; gap: 14px; }
    .keyboard-row { gap: 7px; }
    .key { width: 38px; height: 38px; font-size: 8px; }
    .key.space { width: 230px; }
    .key.backspace, .key.enter-key { width: 58px; }
    .theme-toggle { top: 10px; right: 12px; font-size: 22px; }
}

@media (max-width: 480px) {
    .paper-sheet { padding: 13px; min-height: 110px; font-size: 0.95rem; }
    .typewriter-body { padding: 12px; gap: 10px; }
    .keyboard-row { gap: 5px; }
    .key { width: 32px; height: 32px; font-size: 7px; }
    .key.space { width: 190px; }
    .key.backspace, .key.enter-key { width: 50px; }
}

.controls{
    display:flex;
    gap:10px;
    margin-top:10px;
    align-items:center;
    flex-wrap:wrap;
}

.controls button{
    padding:8px 14px;
    border:none;
    border-radius:6px;
    cursor:pointer;
    font-family:inherit;
}

#pageCounter{
    color:white;
    font-weight:bold;
}

#copyBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.counters {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
    flex-wrap: wrap;
    color: white;
    font-weight: bold;
}

.counter-separator {
    opacity: 0.7;
}

#pagesContainer{
    width:100%;
    display:flex;
    flex-direction:column;
    gap:30px;
    align-items:center;
}

.ink{
    color:#000 !important;
    opacity:1 !important;
    filter:none !important;
    font-weight:900;
    -webkit-text-fill-color:#000;
}

.stamp{
    animation:stamp .15s;
}

@keyframes stamp{
    0%{
    transform:scale(1.2);
    }
    100%{
    transform:scale(1);
    }
}

@media print{
    .cursor-paper{
        display:none;
    }
}
