@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,500;9..144,650;9..144,750&display=swap');

:root{--ink:#5f473a;--muted:#7c665a;--paper:#f4ece4;--card:#f1e7dc;--line:#e2d4c5;--orange:#f0a24b;--orange-dark:#ae6423;--dark:#27150f;--dark-soft:#3f2116;--danger:#a83d31;--shadow:0 12px 44px #27150f20}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;font-family:"DM Sans",sans-serif;background:var(--dark);color:var(--ink)}
body{overflow-x:hidden}
button,input,textarea,select{font:inherit}
button{cursor:pointer}
button:disabled{cursor:not-allowed;opacity:.58}
button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible{outline:3px solid var(--orange);outline-offset:3px}
button[hidden],[hidden]{display:none!important}
.app-shell{min-height:100dvh;position:relative;background:var(--paper);display:flex;flex-direction:column}
.app-header{background:linear-gradient(180deg,var(--dark-soft),var(--dark));color:#fff;padding:calc(env(safe-area-inset-top) + 20px) 24px 33px;flex:none}
.header-inner{max-width:960px;margin:auto;text-align:center}
.brand{font:750 clamp(32px,6vw,42px)/1.1 "Fraunces",serif;letter-spacing:-.04em}
.header-subtitle{display:inline-flex;gap:7px;align-items:center;background:none;border:0;color:#fff;font:650 clamp(19px,4vw,24px)/1.3 "Fraunces",serif;padding:11px 14px 0}
.chevron-down{font-family:"DM Sans",sans-serif;font-size:22px;line-height:1}
.main-surface{flex:1;background:radial-gradient(ellipse at 50% 0%,#fff8ed 0%,var(--paper) 50%,#e4d7c8 100%);padding:0 22px 24px;min-height:0}
.view{max-width:960px;margin:-7px auto 0;min-height:0}
#stories-view{height:100%}
.story-card,.paper-panel{background:var(--card);border:1px solid var(--line);border-radius:28px;box-shadow:var(--shadow)}
.story-card{height:calc(100dvh - 207px - env(safe-area-inset-top) - env(safe-area-inset-bottom));min-height:340px;display:flex;flex-direction:column;padding:20px;position:relative}
.story-content{min-height:0;display:flex;flex-direction:column;flex:1}
.story-actions{display:flex;gap:8px;align-items:center;position:relative}
.primary-button,.secondary-button{border:0;border-radius:18px;min-height:49px;padding:10px 20px;font-weight:700;transition:transform .14s,filter .14s}
.primary-button{background:var(--orange);color:var(--dark)}
.secondary-button{background:#e9d8c6;color:var(--ink);border:1px solid #d7bea8}
.primary-button:hover,.secondary-button:hover,.new-story-fab:hover{filter:brightness(1.04);transform:translateY(-1px)}
.story-actions>.primary-button{flex:1}
.icon-button{border:0;background:transparent;color:var(--ink);font-size:33px;width:46px;height:48px;line-height:1}
.overflow-menu{position:absolute;right:0;top:50px;z-index:5;width:168px;background:#fff9f2;border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow);overflow:hidden}
.overflow-menu button{display:block;width:100%;text-align:left;padding:13px 17px;background:none;border:0;color:var(--ink)}
.overflow-menu button:hover{background:#f0e2d3}
.generation-status{display:flex;align-items:center;gap:9px;margin-top:12px;color:var(--muted);font-size:14px}
.spinner{width:16px;height:16px;border:2px solid #d8c1a8;border-top-color:var(--orange-dark);border-radius:50%;animation:spin .85s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.story-title{font:750 clamp(25px,4vw,33px)/1.14 "Fraunces",serif;letter-spacing:-.025em;margin:17px 0 7px;color:var(--ink)}
.story-category{font-size:15px;font-weight:600;color:var(--muted);display:flex;align-items:center;gap:7px}
.story-category:before{content:"◉";color:var(--orange-dark);font-size:15px}
.story-text-scroll{overflow:auto;flex:1;min-height:0;margin-top:14px;scrollbar-color:#bea38d transparent}
.story-text p{font:400 clamp(17px,2.6vw,19px)/1.65 "DM Sans",sans-serif;letter-spacing:.002em;margin:0 0 15px;padding:6px 7px;border-radius:10px}
.story-text p.active{background:#f2c995}
.pagination{display:flex;align-items:center;justify-content:space-between;background:#e9ddd0;border-radius:23px;max-width:300px;width:75%;align-self:center;margin-top:16px;padding:3px 9px;color:var(--ink);font-weight:700}
.pagination button{border:0;background:none;color:var(--muted);font-size:34px;line-height:1;width:44px;height:39px}
.empty-state{display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;flex:1}
.book-art{width:136px;margin-bottom:16px}
.book-art svg{display:block;width:100%}
.empty-state h1{font:750 clamp(28px,5vw,36px)/1.1 "Fraunces",serif;margin:0}
.empty-state p{margin:9px 0;color:var(--muted);font-size:18px}
.new-story-fab{position:fixed;z-index:8;right:max(26px,calc((100vw - 960px)/2 + 28px));bottom:calc(env(safe-area-inset-bottom) + 94px);width:66px;height:66px;border-radius:50%;border:0;background:var(--orange);box-shadow:0 8px 24px #4d2c1a55;color:#fff;font-size:42px;line-height:1}
.bottom-nav{position:sticky;bottom:0;z-index:6;background:linear-gradient(115deg,var(--dark),var(--dark-soft));display:flex;justify-content:center;gap:clamp(12px,8vw,105px);padding:9px 10px calc(env(safe-area-inset-bottom) + 8px);min-height:78px}
.bottom-nav button{min-width:70px;display:flex;align-items:center;flex-direction:column;gap:4px;background:none;border:0;color:#d8c8b8;font-size:13px;font-weight:600}
.bottom-nav button.selected{color:var(--orange)}
.bottom-nav svg{width:26px;height:26px;stroke:currentColor;stroke-width:1.8;fill:none;stroke-linecap:round;stroke-linejoin:round}
.secondary-view{padding-bottom:20px}
.section-heading{padding:19px 3px 17px}
.section-heading h1{font:750 clamp(26px,5vw,34px)/1.1 "Fraunces",serif;margin:0}
.section-heading p{margin:6px 0 0;color:var(--muted)}
.paper-panel{padding:clamp(19px,4vw,30px)}
.field{display:flex;flex-direction:column;gap:7px;margin-bottom:20px;font-weight:700}
.field>span,.choice-field legend{font-size:15px}
.field input,.field textarea,.field select,.modal input,.modal textarea,.modal select{width:100%;background:#fff8f0;color:var(--ink);border:1px solid #cfbaa7;border-radius:15px;padding:13px 15px;min-height:48px;outline:none}
.field textarea{resize:vertical;min-height:85px}
.field input:focus,.field textarea:focus,.field select:focus,.modal input:focus,.modal textarea:focus,.modal select:focus{border-color:var(--orange-dark);box-shadow:0 0 0 3px #f0a24b33}
.field small{font-weight:400;color:var(--muted)}
.choice-field{border:0;margin:0 0 20px;padding:0}
.choice-field legend{font-weight:700;margin-bottom:10px}
.choice-field small{font-weight:400;color:var(--muted)}
.chips{display:flex;gap:7px;flex-wrap:wrap}
.chip{padding:9px 14px;border-radius:999px;border:1px solid #d7bea8;background:#fff8f0;color:var(--ink);font-weight:600}
.chip.active{background:#f9d7ac;border-color:var(--orange-dark)}
.wide-button{width:100%;margin-top:8px}
.settings-panel{display:flex;flex-direction:column;gap:11px}
.account-panel{padding:0 0 18px;border-bottom:1px solid var(--line);margin-bottom:6px}
.account-quota{margin:9px 0 5px;font-weight:600}
.account-reset{font-size:13px;line-height:1.5;color:var(--muted);margin:5px 0 10px}
.switch-row{display:flex;align-items:center;justify-content:space-between;gap:18px;min-height:46px;cursor:pointer;font-weight:600}
.switch-row input{position:absolute;opacity:0}
.switch{width:48px;height:28px;flex:none;border-radius:99px;background:#c9b29c;position:relative;transition:background .2s}
.switch:after{content:"";width:21px;height:21px;border-radius:50%;background:#fff;position:absolute;top:3.5px;left:3.5px;transition:transform .2s}
.switch-row input:checked+.switch{background:var(--orange-dark)}
.switch-row input:checked+.switch:after{transform:translateX(20px)}
.switch-row input:focus-visible+.switch{outline:3px solid var(--orange);outline-offset:3px}
.text-danger{border:0;background:transparent;color:var(--danger);padding:15px 8px;font-weight:700}
.archive-list{display:flex;flex-direction:column;gap:8px}
.archive-row{display:flex;gap:11px;align-items:center;background:#fff8f0;border:1px solid var(--line);border-radius:14px;padding:13px}
.archive-row input{accent-color:var(--orange-dark);width:18px;height:18px}
.archive-row span{font-weight:700}
.archive-row small{display:block;color:var(--muted);margin-top:3px}
.archive-actions{display:flex;gap:12px;margin:15px 0}
.archive-actions>*{flex:1}
.modal{border:0;border-radius:25px;max-width:min(560px,calc(100vw - 28px));width:100%;max-height:min(86dvh,800px);padding:0;background:var(--paper);color:var(--ink);box-shadow:0 24px 70px #12080088}
.modal::backdrop{background:#12080099;backdrop-filter:blur(3px)}
.modal-inner{display:flex;flex-direction:column;max-height:min(86dvh,800px)}
.modal-head{display:flex;align-items:center;justify-content:space-between;gap:15px;padding:20px 23px 11px}
.modal h2{font:750 25px/1.15 "Fraunces",serif;color:var(--ink);margin:0}
.close-button{background:none;border:0;color:var(--muted);font-size:30px;line-height:1}
.modal-body{overflow:auto;padding:9px 23px 16px}
.modal-actions{display:flex;justify-content:flex-end;gap:10px;padding:13px 23px 20px;border-top:1px solid var(--line)}
.modal-body p{line-height:1.55;margin:8px 0 16px}
.modal-body .field{margin-bottom:15px}
.modal-body .inline-choice{display:flex;align-items:center;gap:10px;margin:7px 0;font-weight:600}
.modal-body .inline-choice input{width:18px;min-height:auto;accent-color:var(--orange-dark)}
.modal-body .info-list{padding-left:22px;line-height:1.55}
.modal-body .info-list li{margin:10px 0}
.modal-body .list-button{width:100%;display:flex;justify-content:space-between;align-items:center;background:#fff8f0;border:1px solid var(--line);border-radius:13px;padding:13px;margin:7px 0;color:var(--ink);text-align:left;font-weight:700}
.modal-body .list-button.active{border-color:var(--orange-dark);background:#f9dfbe}
.modal-body .muted{color:var(--muted);font-size:14px}
.modal-body .helper-link{border:0;background:none;color:var(--orange-dark);font-weight:700;padding:5px 0}
.modal-body .option-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}
#toast{position:fixed;z-index:20;bottom:calc(env(safe-area-inset-bottom) + 90px);left:50%;transform:translate(-50%,20px);background:var(--dark);color:#fff;border-radius:14px;padding:12px 17px;box-shadow:var(--shadow);opacity:0;pointer-events:none;transition:opacity .2s,transform .2s;max-width:90vw;text-align:center}
#toast.show{opacity:1;transform:translate(-50%,0)}
@media(min-width:720px){.app-shell{max-width:1050px;margin:auto;box-shadow:0 0 80px #0005}.main-surface{padding-left:42px;padding-right:42px}.story-card{min-height:520px}.bottom-nav{gap:100px}}
@media(max-width:420px){.app-header{padding-bottom:27px}.main-surface{padding-left:14px;padding-right:14px}.story-card{padding:16px;border-radius:24px;height:calc(100dvh - 194px - env(safe-area-inset-top) - env(safe-area-inset-bottom))}.pagination{width:83%}.story-title{font-size:25px}.modal-body .option-grid{grid-template-columns:1fr}.new-story-fab{width:62px;height:62px}}
@media(max-height:650px){.story-card{min-height:270px}.brand{font-size:30px}.app-header{padding-bottom:19px}.story-title{margin-top:9px}.pagination{margin-top:7px}}
