/* --- Typewriter --- */
#toy-typewriter {
    position: relative;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

#typewriter-paper {
    flex: 0 0 auto;
    width: min(100%, 600px);
    max-width: 100%;
    height: clamp(160px, 26vh, 280px);
    min-height: 160px;
    margin-bottom: clamp(12px, 2vw, 20px);
    padding: clamp(16px, 4vw, 30px) clamp(18px, 4vw, 35px);
    border-radius: 4px 4px 2px 2px;
    border: 1px solid rgba(255, 255, 255, 0.42);
    background-color: #f4f1ea;
    background-image:
        radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.72), transparent 46%),
        linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px);
    background-size: 100% 100%, 100% 1.45em;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(0, 0, 0, 0.05);
    color: #1e293b;
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(15px, 3.8vw, 20px);
    line-height: 1.45;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    touch-action: manipulation;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

#typewriter-paper::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 7px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(120, 113, 108, 0.08));
    content: '';
    pointer-events: none;
}

#tw-keyboard-area {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: clamp(6px, 1vw, 10px);
    width: min(100%, 620px);
    padding: 0 0.25rem;
}

.typed-char {
    display: inline-block;
    position: relative;
    text-shadow: 0px 0px 1px rgba(0,0,0,0.3);
    z-index: 2;
}

.typewriter-cursor {
    display: inline-block;
    width: 0.08em;
    height: 1.05em;
    margin-left: 2px;
    background: #0f766e;
    vertical-align: -0.14em;
    animation: typewriter-blink 1.05s steps-end infinite;
}

.tw-controls {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: min(100%, 600px);
    min-height: 44px;
    margin-bottom: 12px;
}

.tw-status {
    color: #94a3b8;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: 0.04em;
    user-select: none;
}

.tw-status.is-near-limit {
    color: #fbbf24;
}

.tw-status.is-at-limit {
    color: #fda4af;
}

.tw-clear {
    align-self: center;
    min-height: 44px;
    margin-top: 2px;
    padding: 9px 16px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.58);
    color: #cbd5e1;
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
}

#typewriter-paper.paper-nudge {
    animation: typewriter-nudge 0.11s ease;
}

#typewriter-paper.margin-bell {
    animation: typewriter-bell 0.42s ease;
}

#typewriter-paper.carriage-return {
    animation: typewriter-carriage 0.28s ease;
}

@keyframes typewriter-blink {
    0%, 46% { opacity: 1; }
    47%, 100% { opacity: 0; }
}

@keyframes typewriter-nudge {
    0%, 100% { transform: translateY(0); }
    45% { transform: translateY(1.5px); }
}

@keyframes typewriter-bell {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    60% { transform: translateX(1px); }
}

@keyframes typewriter-carriage {
    0%, 100% { transform: translateX(0); }
    35% { transform: translateX(5px); }
    70% { transform: translateX(-1px); }
}

.key-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(4px, 1.5vw, 8px);
}

.tw-key {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: var(--tw-key-size);
    min-width: 44px;
    height: var(--tw-key-size);
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 2px solid #94a3b8;
    border-radius: 50%;
    appearance: none;
    -webkit-appearance: none;
    background: radial-gradient(circle at 50% 10%, #f1f5f9, #cbd5e1);
    box-shadow: 0 5px 0 #64748b, 0 8px 10px rgba(0, 0, 0, 0.25), inset 0 2px 3px rgba(255, 255, 255, 0.8);
    color: #0f172a;
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(14px, 3.5vw, 18px);
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.05s, box-shadow 0.05s;
}

.tw-key--space {
    width: min(200px, 52vw);
    min-width: 120px;
    border-radius: 14px;
}

.tw-key--wide {
    width: clamp(56px, 16vw, 72px);
    border-radius: 14px;
}

@media (hover: hover) {
    .tw-clear:hover {
        border-color: rgba(94, 234, 212, 0.5);
        color: #ffffff;
    }
}

.tw-key.pressed {
    transform: translateY(5px);
    background: radial-gradient(circle at 50% 10%, #ffffff, #e2e8f0);
    box-shadow: 0 0 0 #64748b, 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 2px 3px rgba(255, 255, 255, 0.8);
}
