/* --- 
Theme: 江南园林 (Jiangnan Garden)
--- */

/* --- General Setup & Font --- */
:root {
    --bg-color: #3d2c1d; /* Dark Wood */
    --panel-bg: rgba(245, 247, 246, 0.9); /* White Jade with transparency */
    --text-color: #3a2e28;
    --title-color: #2c1e18;
    --border-color: #8a704c; /* Bronze/Wood Accent */
    --primary-color: #6a8b6a; /* Muted Jade Green */
    --accent-color: #a8453c; /* Seal Red */
    --shadow-color: rgba(0, 0, 0, 0.3);
    --light-shadow: rgba(58, 46, 40, 0.2);
    --font-serif: 'Ma Shan Zheng', 'KaiTi', 'STKaiti', '楷体', serif;
    --font-sans: 'ZCOOL KuaiLe', 'Noto Sans SC', sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&family=ZCOOL+KuaiLe&display=swap');

body {
    font-family: var(--font-serif);
    background-color: var(--bg-color);
    background-image: url('data:image/svg+xml;charset=UTF-8,%3Csvg width="80" height="80" viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%234a382a" fill-opacity="0.2"%3E%3Cpath d="M50 50c0-5.523 4.477-10 10-10s10 4.477 10 10-4.477 10-10 10c-5.523 0-10-4.477-10-10zM10 10c0-5.523 4.477-10 10-10s10 4.477 10 10-4.477 10-10 10c-5.523 0-10-4.477-10-10z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
    background-attachment: fixed;
    color: var(--text-color);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
    box-sizing: border-box;
    position: relative;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 15% 85%, rgba(106, 139, 106, 0.1), transparent 40%);
    pointer-events: none;
    z-index: -1;
}


/* --- Main Container as a Wooden Frame --- */
#app-container {
    width: 100%;
    max-width: 1000px;
    height: 90vh;
    max-height: 800px;
    background: rgba(45, 30, 20, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    border: 8px solid #5a4a3a;
    box-shadow: 
        inset 0 0 0 2px #3d2c1d,
        0 10px 40px var(--shadow-color);
}

/* --- View Management --- */
.view {
    display: none;
    flex-grow: 1;
    flex-direction: column;
    overflow: hidden;
    padding: 1rem;
}
.view.active {
    display: flex;
}

/* --- Login View: Jade Tablet --- */
#login-view {
    justify-content: center;
    align-items: center;
    text-align: center;
}

#login-view h1 {
    font-family: var(--font-sans);
    font-size: 3.5rem;
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.3), 2px 2px 5px var(--shadow-color);
    margin-bottom: 2rem;
    letter-spacing: 0.2em;
}

#login-view p {
    color: #eee;
    text-shadow: 1px 1px 3px var(--shadow-color);
    font-size: 1.1rem;
    margin-bottom: 2.5rem;
}

#login-form {
    background: var(--panel-bg);
    padding: 2.5rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px var(--shadow-color);
    backdrop-filter: blur(5px);
    width: 100%;
    max-width: 400px;
}

#login-form input {
    display: block;
    margin: 1.2rem auto;
    padding: 0.8rem 1rem;
    width: 90%;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

#login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(106, 139, 106, 0.5);
}

.login-button {
    display: inline-block;
    padding: 0.8rem 2.5rem;
    background: linear-gradient(145deg, var(--accent-color), #c95c53);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50px;
    cursor: pointer;
    margin-top: 1.5rem;
    font-family: var(--font-sans);
    font-size: 1.2rem;
    font-weight: bold;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), inset 0 2px 2px rgba(255, 255, 255, 0.2);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.login-button:hover {
    background: linear-gradient(145deg, #c95c53, var(--accent-color));
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), inset 0 2px 3px rgba(255, 255, 255, 0.3);
    color: white;
}

.error-message {
    color: var(--accent-color);
    height: 1.5rem;
    font-weight: bold;
}

/* --- Game View: Lattice Window Layout --- */
#game-view {
    padding: 0;
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header"
        "status main"
        "status action";
    gap: 2px;
    background-color: #5a4a3a;
}

#game-header, #status-panel, #main-content, #action-area {
    background: var(--panel-bg);
    padding: 1rem;
}

#game-header {
    grid-area: header;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#game-header h1 {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1.8rem;
    color: var(--title-color);
}

.logout-button {
    padding: 0.4rem 0.8rem;
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.logout-button:hover {
    background: rgba(0,0,0,0.05);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

#status-panel {
    grid-area: status;
    padding: 1.5rem;
    overflow-y: auto;
    border-right: 2px solid #5a4a3a;
}
#status-panel p {
    font-family: var(--font-sans);
    font-weight: bold;
    color: var(--title-color);
    font-size: 1.2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 0;
}
#character-status {
    font-size: 0.95rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Collapsible Section Styling */
#character-status details {
    margin-bottom: 0.5rem;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 4px;
}

#character-status summary {
    font-weight: bold;
    cursor: pointer;
    padding: 0.5rem;
    background-color: rgba(0,0,0,0.03);
    outline: none;
}

#character-status summary::marker {
    color: var(--primary-color);
}

#character-status .details-content {
    padding: 0.5rem 0.5rem 0.5rem 1.5rem;
    background-color: rgba(0,0,0,0.01);
}

.property-item {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
}

.property-key {
    font-weight: bold;
    color: var(--title-color);
}

.property-value {
    color: var(--text-color);
}


#main-content {
    grid-area: main;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
}

#narrative-window {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    line-height: 2;
    font-size: 1.1rem;
}

/* Narrative content styling */
#narrative-window p, #narrative-window h1, #narrative-window h2, #narrative-window h3, #narrative-window ul, #narrative-window ol, #narrative-window blockquote {
    margin: 0 0 1.5em 0;
}

#narrative-window h1, #narrative-window h2, #narrative-window h3 {
    font-family: var(--font-sans);
    color: var(--title-color);
    margin-bottom: 1rem;
}

#narrative-window ul, #narrative-window ol {
    padding-left: 2em;
}

#narrative-window blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1em;
    margin-left: 0.5em;
    color: #555;
    font-style: italic;
}

#narrative-window code {
    background-color: #e8e8e8;
    border-radius: 3px;
    padding: 0.2em 0.4em;
    font-family: monospace;
}
#narrative-window pre {
    background-color: #e8e8e8;
    padding: 1em;
    border-radius: 4px;
    overflow-x: auto;
}
#narrative-window pre code {
    padding: 0;
    background: none;
}


/* --- Action Footer --- */
#action-area {
    grid-area: action;
    border-top: 2px solid #5a4a3a;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.action-input-row {
    display: flex;
    gap: 0.8rem;
}

#action-input {
    flex-grow: 1;
    padding: 0.8rem 1.2rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s ease;
}

#action-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(106, 139, 106, 0.5);
}

#action-button, #start-trial-button {
    padding: 0.8rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px var(--light-shadow);
}

#action-button:hover:not(:disabled), #start-trial-button:hover:not(:disabled) {
    background: #82a882;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px var(--light-shadow);
}

#start-trial-button {
    background: var(--accent-color);
}
#start-trial-button:hover:not(:disabled) {
    background: #c95c53;
}

#action-input:disabled, #action-button:disabled {
    background: #e9e9e9;
    color: #999;
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
    box-shadow: none;
}

/* --- Overlays & Spinners --- */
.hidden { display: none !important; }

.spinner-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- Roll Animation --- */
#roll-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
#roll-panel {
    background: var(--panel-bg);
    padding: 3rem 4rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    text-align: center;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
.dice-cup {
    font-size: 5rem;
    animation: diceRoll 1s cubic-bezier(.36,.07,.19,.97) both;
}
#roll-details {
    font-size: 1.3rem; margin: 1.5rem 0;
    color: var(--title-color); font-weight: bold;
}
#roll-result-display {
    margin-top: 2rem; font-size: 2rem; font-weight: bold;
}
#roll-value {
    font-size: 3rem; margin-left: 1rem; color: var(--text-color);
}
.outcome-大成功 { color: var(--accent-color); }
.outcome-成功 { color: var(--primary-color); }
.outcome-失败 { color: #888; }
.outcome-大失败 { color: #b8463f; }

@keyframes diceRoll {
  0% { transform: rotate(0); }
  100% { transform: rotate(360deg); }
}

/* --- Responsive Design --- */
@media (max-width: 850px) {
    body {
        padding: 0;
    }
    #app-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
        border: none;
    }
    #game-view {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas:
            "header"
            "status"
            "main"
            "action";
    }
    #status-panel {
        border-right: none;
        border-bottom: 2px solid #5a4a3a;
        max-height: 150px;
        padding: 0.5rem 1rem;
    }
    #narrative-window { padding: 1rem; }
    .action-input-row { flex-direction: column; gap: 0.5rem; }
    #action-button { width: 100%; }
}