Files
ReSekai/src/pages/GamePage.css
T
Alexej Wolff 68c2b129fa Major refactor: security, performance, and code organization
Security:
- DeepSeek API moved to server-side proxy with rate limiting (20 req/min)
- Whitelist validation for all POST/PUT routes
- Cookie security (secure, sameSite, httpOnly in production)
- Input validation for messages, tokens, temperature
- Sanitized hasOwnProperty to prevent prototype pollution

Performance:
- Lazy loading for chat messages (sliding window of 20)
- Streaming response throttling (50ms batches)
- Scroll optimization (only scroll on new messages)
- AbortController fix for stop button

Code organization:
- GamePage refactored from ~1170 to ~750 lines
- New hooks: useGameSession, useStreamingResponse, useCharacterDetection, useLazyMessages
- New components: MessageList, ChatInput, SessionSelector, CharacterPanel
- Fixed ESLint errors

Features:
- OOC mode button for direct AI instructions
- Message versions (aiResponse) now persist to DB
- playerId saved in sessions
2026-05-05 23:41:52 +02:00

1015 lines
17 KiB
CSS

.game-page {
height: 100vh;
height: 100dvh;
display: flex;
flex-direction: column;
background: #000;
padding-top: env(safe-area-inset-top);
overflow: hidden;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
touch-action: none;
}
.game-page * {
touch-action: pan-y;
}
.game-error {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
gap: 1rem;
}
.game-header {
flex-shrink: 0;
z-index: 10;
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.75rem 1rem;
padding-left: max(1rem, env(safe-area-inset-left));
padding-right: max(1rem, env(safe-area-inset-right));
background: #0a0a0a;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.back-btn {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
background: transparent;
border-radius: 50%;
color: #999;
text-decoration: none;
font-size: 1.1rem;
transition: all 0.2s;
}
.back-btn:hover {
background: rgba(255, 255, 255, 0.1);
color: #fff;
}
.header-info {
flex: 1;
min-width: 0;
}
.header-info h1 {
font-size: 1rem;
margin: 0;
color: #fff;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-session {
position: relative;
}
.session-selector {
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 16px;
padding: 0.35rem 0.7rem;
font-size: 0.8rem;
color: #999;
cursor: pointer;
transition: all 0.2s;
}
.session-selector:hover {
background: rgba(255, 255, 255, 0.12);
color: #fff;
}
.session-menu {
position: absolute;
top: 100%;
right: 0;
margin-top: 0.5rem;
background: #141414;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 12px;
min-width: 220px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
z-index: 100;
overflow: hidden;
}
.session-menu-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem 1rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
font-size: 0.8rem;
color: #666;
}
.new-session-btn {
background: rgba(34, 197, 94, 0.15);
border: none;
border-radius: 12px;
padding: 0.3rem 0.6rem;
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s;
}
.new-session-btn:hover {
background: rgba(34, 197, 94, 0.25);
}
.session-list {
max-height: 250px;
overflow-y: auto;
}
.session-item {
display: flex;
align-items: center;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.session-item:last-child {
border-bottom: none;
}
.session-item.active {
background: rgba(37, 99, 235, 0.12);
}
.session-name {
flex: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.2rem;
padding: 0.65rem 1rem;
background: none;
border: none;
color: #ddd;
font-size: 0.85rem;
cursor: pointer;
text-align: left;
transition: background 0.2s;
}
.session-name:hover {
background: rgba(255, 255, 255, 0.05);
}
.session-messages {
font-size: 0.7rem;
color: #555;
}
.delete-session-btn {
background: none;
border: none;
padding: 0.5rem;
margin-right: 0.5rem;
font-size: 0.85rem;
cursor: pointer;
opacity: 0.5;
transition: opacity 0.2s;
}
.delete-session-btn:hover {
opacity: 1;
}
.session-delete-btn {
background: none;
border: none;
padding: 0.5rem;
margin-right: 0.5rem;
font-size: 0.85rem;
cursor: pointer;
opacity: 0.4;
transition: opacity 0.2s;
}
.session-delete-btn:hover {
opacity: 1;
}
.header-protagonist {
font-size: 0.8rem;
color: #666;
}
.header-stats {
display: flex;
gap: 0.4rem;
}
.stat-badge {
padding: 0.35rem 0.65rem;
border-radius: 16px;
font-size: 0.75rem;
font-weight: 500;
background: rgba(255, 255, 255, 0.08);
color: #888;
}
.stat-badge.health {
background: rgba(239, 68, 68, 0.12);
color: #f87171;
}
.stat-badge.location {
background: rgba(37, 99, 235, 0.12);
color: #60a5fa;
}
.game-content {
flex: 1;
min-height: 0;
min-width: 0;
display: flex;
flex-direction: column;
overflow: hidden;
position: relative;
width: 100%;
}
.scroll-to-bottom-btn {
position: absolute;
bottom: 5rem;
right: 1rem;
width: 40px;
height: 40px;
background: rgba(30, 30, 30, 0.9);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 50%;
color: #fff;
font-size: 1.25rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
z-index: 5;
transition: all 0.2s;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.scroll-to-bottom-btn:hover {
background: rgba(50, 50, 50, 0.95);
transform: scale(1.05);
}
.messages-container {
flex: 1;
overflow-y: auto;
overflow-x: hidden;
overscroll-behavior: contain;
-webkit-overflow-scrolling: touch;
touch-action: pan-y;
padding: 1rem;
padding-left: max(1rem, env(safe-area-inset-left));
padding-right: max(1rem, env(safe-area-inset-right));
padding-bottom: 1rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
width: 100%;
box-sizing: border-box;
}
.load-more-messages-btn {
align-self: center;
padding: 0.5rem 1rem;
margin-bottom: 0.5rem;
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 20px;
color: rgba(255, 255, 255, 0.7);
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s ease;
}
.load-more-messages-btn:hover {
background: rgba(255, 255, 255, 0.12);
color: rgba(255, 255, 255, 0.9);
}
.load-more-messages-btn:active {
transform: scale(0.98);
}
.message {
max-width: 88%;
animation: fadeIn 0.25s ease;
word-wrap: break-word;
overflow-wrap: break-word;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.message.user {
align-self: flex-end;
}
.message.assistant {
align-self: flex-start;
}
.message-content {
padding: 0.875rem 1rem;
border-radius: 18px;
line-height: 1.7;
font-size: 1.1rem;
}
@media (max-width: 768px) {
.message-content {
font-size: 22px;
line-height: 1.8;
}
}
.message.user .message-content {
background: #2563eb;
color: white;
border-bottom-right-radius: 6px;
}
.message.assistant .message-content {
background: transparent;
color: #e5e5e5;
border: none;
padding: 0.5rem 0;
}
.message-content p {
margin: 0;
}
.message-content p + p {
margin-top: 0.75rem;
}
/* Markdown стили */
.message-content strong {
font-weight: 700;
color: #fff;
}
.message-content em {
font-style: italic;
color: #bbb;
}
.message-content ul,
.message-content ol {
margin: 0.5rem 0;
padding-left: 1.5rem;
}
.message-content li {
margin: 0.25rem 0;
}
.message-content blockquote {
border-left: 2px solid #2563eb;
padding-left: 0.875rem;
margin: 0.5rem 0;
color: #999;
font-style: italic;
}
.message-content code {
background: #252525;
padding: 0.125rem 0.35rem;
border-radius: 4px;
font-family: monospace;
font-size: 0.85em;
}
.message-content hr {
border: none;
border-top: 1px solid rgba(255, 255, 255, 0.1);
margin: 0.75rem 0;
}
.message-footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 0.25rem;
padding: 0 0.4rem;
}
.message-time {
font-size: 0.65rem;
color: #444;
}
.message.user .message-time {
color: rgba(255, 255, 255, 0.4);
}
.message.user .message-footer {
flex-direction: row-reverse;
}
.message-actions {
display: flex;
align-items: center;
gap: 0.5rem;
opacity: 0;
transition: opacity 0.2s;
}
.message:hover .message-actions {
opacity: 1;
}
.edit-btn {
background: none;
border: none;
font-size: 0.75rem;
cursor: pointer;
padding: 0.25rem;
opacity: 0.6;
transition: opacity 0.2s;
}
.edit-btn:hover {
opacity: 1;
}
.version-switcher {
display: flex;
align-items: center;
gap: 0.25rem;
background: rgba(255, 255, 255, 0.1);
border-radius: 12px;
padding: 0.15rem 0.35rem;
}
.version-btn {
background: none;
border: none;
color: #888;
font-size: 0.9rem;
cursor: pointer;
padding: 0 0.25rem;
line-height: 1;
transition: color 0.2s;
}
.version-btn:hover {
color: #fff;
}
.version-indicator {
font-size: 0.7rem;
color: #666;
min-width: 2rem;
text-align: center;
}
/* Message editing */
.message-edit-form {
width: 100%;
}
.message-edit-textarea {
width: 100%;
min-height: 60px;
padding: 0.75rem;
background: #1a1a1a;
border: 1px solid rgba(37, 99, 235, 0.5);
border-radius: 12px;
color: white;
font-size: 0.95rem;
font-family: inherit;
resize: vertical;
line-height: 1.4;
}
.message-edit-textarea:focus {
outline: none;
border-color: #2563eb;
}
.message-edit-actions {
display: flex;
justify-content: flex-end;
gap: 0.5rem;
margin-top: 0.5rem;
}
.edit-cancel-btn,
.edit-save-btn {
padding: 0.4rem 0.75rem;
border: none;
border-radius: 8px;
font-size: 0.8rem;
cursor: pointer;
transition: all 0.2s;
}
.edit-cancel-btn {
background: #333;
color: #aaa;
}
.edit-cancel-btn:hover {
background: #444;
color: #fff;
}
.edit-save-btn {
background: #2563eb;
color: white;
}
.edit-save-btn:hover {
background: #1d4ed8;
}
.message.loading .message-content {
padding: 1rem;
}
.typing-indicator {
display: flex;
gap: 4px;
}
.typing-indicator span {
width: 6px;
height: 6px;
background: #2563eb;
border-radius: 50%;
animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) {
animation-delay: 0s;
}
.typing-indicator span:nth-child(2) {
animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes typing {
0%,
60%,
100% {
transform: translateY(0);
opacity: 0.3;
}
30% {
transform: translateY(-6px);
opacity: 1;
}
}
.error-message {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.65rem 0.875rem;
background: rgba(239, 68, 68, 0.1);
border: 1px solid rgba(239, 68, 68, 0.2);
border-radius: 12px;
color: #f87171;
font-size: 0.85rem;
}
.error-message button {
background: none;
border: none;
color: #f87171;
cursor: pointer;
padding: 0.25rem;
}
.quick-actions {
display: flex;
gap: 0.5rem;
padding: 0.75rem 1.5rem;
overflow-x: auto;
background: #131313;
}
.quick-actions button {
padding: 0.5rem 1rem;
background: #222;
border: 1px solid #333;
border-radius: 20px;
color: #aaa;
font-size: 0.85rem;
cursor: pointer;
white-space: nowrap;
transition: all 0.2s;
}
.quick-actions button:hover {
background: #2a2a2a;
color: #fff;
border-color: #667eea;
}
.input-container {
flex-shrink: 0;
display: flex;
align-items: flex-end;
gap: 0.5rem;
margin: 0.5rem;
margin-left: max(0.5rem, env(safe-area-inset-left));
margin-right: max(0.5rem, env(safe-area-inset-right));
margin-bottom: max(0.5rem, env(safe-area-inset-bottom));
padding: 0.5rem;
background: #1a1a1a;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 24px;
}
.input-container textarea {
flex: 1;
min-height: 36px;
max-height: 120px;
padding: 0.5rem 1rem;
background: transparent;
border: none;
border-radius: 18px;
color: white;
font-size: 16px; /* 16px prevents iOS zoom on focus */
font-family: inherit;
resize: none;
transition: height 0.1s ease;
overflow-y: auto;
line-height: 1.4;
touch-action: manipulation;
-webkit-appearance: none;
appearance: none;
/* iOS specific */
-webkit-text-size-adjust: 100%;
text-decoration: none;
}
.input-container textarea:focus {
outline: none;
}
.input-container textarea::placeholder {
color: #666;
}
.send-btn {
width: 36px;
min-width: 36px;
height: 36px;
background: #2563eb;
border: none;
border-radius: 50%;
color: white;
font-size: 0.95rem;
cursor: pointer;
transition: all 0.2s;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.send-btn:hover:not(:disabled) {
background: #1d4ed8;
}
.send-btn:disabled {
opacity: 0.3;
cursor: not-allowed;
}
.stop-btn {
width: 36px;
min-width: 36px;
height: 36px;
background: #dc2626;
border: none;
border-radius: 50%;
color: white;
font-size: 0.95rem;
cursor: pointer;
transition: all 0.2s;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.stop-btn:hover {
background: #b91c1c;
}
/* OOC Mode Button */
.ooc-btn {
padding: 0.4rem 0.6rem;
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
color: #888;
font-size: 0.7rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
flex-shrink: 0;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.ooc-btn:hover {
background: rgba(255, 255, 255, 0.1);
color: #aaa;
}
.ooc-btn.active {
background: #f59e0b;
border-color: #f59e0b;
color: #000;
}
.ooc-btn.active:hover {
background: #d97706;
border-color: #d97706;
}
/* OOC Mode Input Container */
.input-container.ooc-mode {
border-color: #f59e0b;
background: rgba(245, 158, 11, 0.1);
}
.input-container.ooc-mode textarea::placeholder {
color: #f59e0b;
}
/* Streaming message animation */
.message.streaming .message-text {
position: relative;
}
.message.streaming .message-text::after {
content: "▋";
animation: blink 1s infinite;
margin-left: 2px;
}
/* Game Layout with Character Panel */
.game-layout {
flex: 1;
display: flex;
min-height: 0;
min-width: 0;
overflow: hidden;
position: relative;
width: 100%;
}
.character-panel {
width: 350px;
min-width: 350px;
height: 100%;
position: relative;
overflow: hidden;
flex-shrink: 0;
background: #0a0a0a;
border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.character-panel img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: top center;
}
.character-panel-info {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 1rem;
background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.character-panel-name {
font-size: 1.25rem;
font-weight: 600;
color: #fff;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}
.character-panel-role {
font-size: 0.85rem;
color: #aaa;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
/* Desktop layout */
@media (min-width: 769px) {
.game-layout.has-character .game-content {
flex: 1;
}
}
/* Mobile: character as background */
@media (max-width: 768px) {
.character-panel {
display: none;
}
.game-layout {
flex-direction: column;
}
.game-layout .game-content {
width: 100%;
max-width: 100%;
}
.game-layout.has-character {
position: relative;
}
.game-layout.has-character::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: var(--character-bg);
background-size: cover;
background-position: top center;
opacity: 0.15;
pointer-events: none;
z-index: 0;
}
.game-layout.has-character .game-content {
position: relative;
z-index: 1;
}
.game-layout.has-character .messages-container {
background: transparent;
}
.game-layout.has-character .message {
background: transparent;
}
.game-layout.has-character .input-container {
background: rgba(10, 10, 10, 0.9);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
}
@keyframes blink {
0%,
50% {
opacity: 1;
}
51%,
100% {
opacity: 0;
}
}
/* Скроллбар */
.messages-container::-webkit-scrollbar {
width: 6px;
}
.messages-container::-webkit-scrollbar-track {
background: transparent;
}
.messages-container::-webkit-scrollbar-thumb {
background: #333;
border-radius: 3px;
}
.messages-container::-webkit-scrollbar-thumb:hover {
background: #444;
}
@media (max-width: 600px) {
.game-header {
padding: 0.5rem 0.75rem;
gap: 0.5rem;
}
.header-info h1 {
font-size: 1rem;
}
.header-stats {
display: none;
}
.messages-container {
padding: 0.75rem;
}
.message {
max-width: 92%;
}
.message-content {
padding: 0.75rem 0.875rem;
font-size: 1rem;
}
.quick-actions {
padding: 0.5rem 0.75rem;
}
.input-container {
margin: 0.375rem;
margin-bottom: max(0.375rem, env(safe-area-inset-bottom));
padding: 0.375rem;
}
.input-container textarea {
min-height: 32px;
padding: 0.4rem 0.875rem;
font-size: 16px; /* Минимум 16px чтобы iOS не зумил */
}
.send-btn,
.stop-btn {
width: 32px;
min-width: 32px;
height: 32px;
}
.session-selector {
font-size: 0.75rem;
padding: 0.25rem 0.5rem;
}
.session-menu {
min-width: 200px;
right: 0;
left: auto;
}
.scroll-to-bottom-btn {
width: 36px;
height: 36px;
bottom: 4.5rem;
right: 0.75rem;
font-size: 1rem;
}
.message-actions {
opacity: 1;
}
.message-edit-textarea {
font-size: 0.9rem;
}
.edit-cancel-btn,
.edit-save-btn {
font-size: 0.75rem;
padding: 0.35rem 0.6rem;
}
}