feature: Add responsive styles

This commit is contained in:
Keith Solomon
2025-09-01 12:54:16 -05:00
parent 6881f654a9
commit 93b7f7b49d
3 changed files with 89 additions and 23 deletions

16
app.js
View File

@@ -106,3 +106,19 @@ async function resetGame() {
} }
window.addEventListener('DOMContentLoaded', onLoad); window.addEventListener('DOMContentLoaded', onLoad);
// Back to Top: show after scrolling, smooth-scroll on click
function initBackToTop() {
const btn = document.getElementById('backToTop');
if (!btn) return;
const onScroll = () => {
if (window.scrollY > 200) btn.classList.add('show'); else btn.classList.remove('show');
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
btn.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
window.addEventListener('DOMContentLoaded', initBackToTop);

View File

@@ -22,7 +22,7 @@
<section class="panel"> <section class="panel">
<h2>Actions</h2> <h2>Actions</h2>
<div class="content"> <div class="content">
<div class="row"> <div class="row actions">
<button data-action onclick="doAction('status')">Check Status</button> <button data-action onclick="doAction('status')">Check Status</button>
<button data-action onclick="handleWork()">Go to Work</button> <button data-action onclick="handleWork()">Go to Work</button>
<button data-action onclick="handleSleep()">Sleep</button> <button data-action onclick="handleSleep()">Sleep</button>
@@ -54,7 +54,7 @@
<div id="state" class="content"></div> <div id="state" class="content"></div>
</section> </section>
</main> </main>
<button id="backToTop" aria-label="Back to top" title="Back to top"> Top</button>
<script src="app.js"></script> <script src="app.js"></script>
</body> </body>
</html> </html>

View File

@@ -12,6 +12,8 @@ header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 12px 16px; padding: 12px 16px;
flex-wrap: wrap;
gap: 8px;
} }
h1 { h1 {
@@ -21,33 +23,38 @@ h1 {
main { main {
display: grid; display: grid;
gap: 16px; gap: 12px;
grid-template-columns: 300px 1fr; grid-template-columns: 1fr;
padding: 16px; padding: 12px;
max-width: 1200px;
margin: 0 auto;
} }
.panel { .panel {
background: #111827; background: #111827;
border: 1px solid #27324a; border: 1px solid #27324a;
border-radius: 8px; border-radius: 8px;
}
h2 { .panel h2 {
color: #a3b5d9; color: #a3b5d9;
font-size: 14px; font-size: 14px;
margin: 0; margin: 0;
padding: 12px 12px 0; padding: 12px 12px 0;
} }
.content { padding: 12px; } .panel .content { padding: 12px; }
&.log { grid-column: 1 / span 2; } .panel.log,
.panel.state {
grid-column: 1 / -1;
} }
#log { #log {
background: #0b1020; background: #0b1020;
color: #e9eef8; color: #e9eef8;
max-height: 60vh; max-height: 50vh;
min-height: 360px; min-height: 240px;
overflow: auto; overflow: auto;
white-space: pre-wrap; white-space: pre-wrap;
} }
@@ -58,20 +65,27 @@ main {
gap: 8px; gap: 8px;
} }
/* Stack action buttons on small screens */
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button { button {
background: #1f2a44; background: #1f2a44;
border: 1px solid #2c3a5e; border: 1px solid #2c3a5e;
border-radius: 6px; border-radius: 6px;
color: #e9eef8; color: #e9eef8;
cursor: pointer; cursor: pointer;
padding: 8px 10px; padding: 10px 12px;
}
&:hover { background: #263356; } button:hover { background: #263356; }
&:disabled { button:disabled {
cursor: not-allowed; cursor: not-allowed;
opacity: 0.5; opacity: 0.5;
}
} }
.hidden { .hidden {
@@ -94,6 +108,42 @@ button {
gap: 8px; gap: 8px;
justify-content: space-between; justify-content: space-between;
margin: 2px 0; margin: 2px 0;
}
.label { color: #a3b5d9; }
.kv .label { color: #a3b5d9; }
@media (min-width: 700px) {
main { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 16px; }
#log { max-height: 60vh; }
.actions { display: flex; flex-wrap: wrap; }
}
@media (min-width: 1024px) {
main { grid-template-columns: 320px 1fr; }
}
/* Back to Top */
#backToTop {
position: fixed;
right: 16px;
bottom: 16px;
z-index: 1000;
background: #1f2a44;
border: 1px solid #2c3a5e;
color: #e9eef8;
border-radius: 999px;
padding: 10px 14px;
box-shadow: 0 6px 16px rgba(0,0,0,0.35);
opacity: 0;
pointer-events: none;
transform: translateY(10px);
transition: opacity .2s ease, transform .2s ease;
}
#backToTop:hover { background: #263356; }
#backToTop.show {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
} }