@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Rajdhani:wght@400;600;700&display=swap');

:root {
  --bg:       #EBEBEB;
  --bg-card:  #E0E0E0;
  --punch:    #D2D2D2;
  --green:    #22C55E;
  --green-dk: #16A34A;
  --red:      #EF4444;
  --red-dk:   #DC2626;
  --orange:   #F97316;
  --orange-dk:#EA580C;
  --blue:     #3B82F6;
  --blue-dk:  #2563EB;
  --text:     #111;
  --sub:      #777;
  --btn-size: 180px;
}
/* Scale up on larger screens */
@media (min-width: 768px) {
  :root { --btn-size: 220px; }
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Rajdhani', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: .02em;
  transition: background .25s ease;
}

/* Screen management */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

/* Login screen — single view, centered */
#screen-login.active {
  min-height: 100vh; min-height: 100dvh;
  align-items: center; justify-content: center;
  padding: 40px 28px; gap: 28px;
}

/* Punch screen — scroll-snap container with 2 sections */
#screen-punch.active {
  height: 100vh; height: 100dvh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
#screen-punch::-webkit-scrollbar { width: 0; }

.punch-section,
.log-section {
  min-height: 100vh; min-height: 100dvh;
  width: 100%;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 40px 28px 64px;
  gap: 32px;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  flex-shrink: 0;
  position: relative;
}
@media (min-width: 768px) {
  .punch-section,
  .log-section { padding: 60px 40px 80px; gap: 40px; }
}
.punch-section { justify-content: flex-start; }
.log-section   { justify-content: flex-start; padding-top: 56px; gap: 20px; }
@media (min-width: 768px) {
  .log-section { padding-top: 72px; gap: 24px; }
}

/* Flex spacer to keep punch area vertically centered on tall screens */
.punch-section .punch-area { margin-top: auto; }
.punch-section .scroll-hint-wrap { margin-top: auto; padding-top: 24px; }

/* Scroll hint chevron */
.scroll-hint-wrap {
  display: flex; justify-content: center;
}
.scroll-hint {
  font-family: 'Share Tech Mono', monospace; font-size: .6rem;
  letter-spacing: .2em; color: var(--sub);
  opacity: .6; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  animation: hintBob 1.8s ease-in-out infinite;
  transition: color .2s, opacity .2s;
}
body.state-success .scroll-hint,
body.state-fail    .scroll-hint,
body.state-waiting .scroll-hint,
body.state-offline .scroll-hint,
body.state-loading .scroll-hint { color: rgba(255,255,255,.65); }
@keyframes hintBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(6px); }
}

/* Login screen */
#screen-login.active { justify-content: center; gap: 28px; }
.login-header { text-align: center; }
.login-header h1 { font-family: 'Share Tech Mono', monospace; font-size: 1.9rem; letter-spacing: .04em; text-transform: uppercase; }
.login-header p { font-family: 'Share Tech Mono', monospace; font-size: .7rem; color: var(--sub); margin-top: 6px; letter-spacing: .18em; text-transform: uppercase; }
.google-btn {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card); border: 1.5px solid rgba(0,0,0,.12);
  border-radius: 4px; padding: 14px 24px;
  font-family: 'Share Tech Mono', monospace; font-size: .9rem;
  letter-spacing: .06em; cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.google-btn:hover { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(59,130,246,.18); }
.login-error { font-family: 'Share Tech Mono', monospace; font-size: .72rem; color: var(--red); letter-spacing: .08em; text-align: center; }
.login-sub { font-family: 'Share Tech Mono', monospace; font-size: .65rem; color: var(--sub); letter-spacing: .1em; text-align: center; }

/* Body state colors — override background */
body.state-loading { background: var(--blue); }
body.state-success { background: var(--green); }
body.state-fail    { background: var(--red); }
body.state-waiting { background: var(--orange); }
body.state-offline { background: var(--red); }

/* Header */
.header { text-align: center; position: relative; width: 100%; max-width: 340px; }
.header h1 { font-family: 'Share Tech Mono', monospace; font-size: 2.2rem; letter-spacing: .04em; text-transform: uppercase; transition: color .2s; }
.header p { font-family: 'Share Tech Mono', monospace; font-size: .75rem; color: var(--sub); margin-top: 8px; letter-spacing: .18em; text-transform: uppercase; transition: color .2s; }
@media (min-width: 768px) {
  .header { max-width: 420px; }
  .header h1 { font-size: 2.6rem; }
  .header p { font-size: .85rem; letter-spacing: .22em; }
}
body.state-success .header h1,
body.state-fail    .header h1,
body.state-waiting .header h1,
body.state-offline .header h1,
body.state-loading .header h1 { color: #fff; }
body.state-success .header p,
body.state-fail    .header p,
body.state-waiting .header p,
body.state-offline .header p,
body.state-loading .header p { color: rgba(255,255,255,.7); }
.signout-btn {
  position: absolute; right: 0; top: 0;
  background: none; border: none; cursor: pointer;
  font-family: 'Share Tech Mono', monospace; font-size: .6rem;
  color: var(--sub); letter-spacing: .1em; text-transform: uppercase;
  padding: 4px; transition: color .2s;
}
body.state-success .signout-btn,
body.state-fail    .signout-btn,
body.state-waiting .signout-btn,
body.state-offline .signout-btn,
body.state-loading .signout-btn { color: rgba(255,255,255,.75); }

/* User card */
.user-card {
  width: 100%; max-width: 340px;
  background: var(--bg-card); border-radius: 4px;
  padding: 14px 18px; border: 1px solid rgba(0,0,0,.06);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  transition: background .2s, border-color .2s;
}
@media (min-width: 768px) {
  .user-card {
    max-width: 420px;
    padding: 18px 22px;
  }
  .user-name { font-size: 1.15rem; }
  .user-meta { font-size: .85rem; }
}
body.state-success .user-card,
body.state-fail    .user-card,
body.state-waiting .user-card,
body.state-offline .user-card,
body.state-loading .user-card { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.2); }
.user-name {
  font-family: 'Rajdhani', sans-serif; font-weight: 700; font-size: 1rem;
  letter-spacing: .06em; text-transform: uppercase; transition: color .2s;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.state-success .user-name,
body.state-fail    .user-name,
body.state-waiting .user-name,
body.state-offline .user-name,
body.state-loading .user-name { color: #fff; }
.user-meta {
  font-family: 'Share Tech Mono', monospace; font-size: .75rem;
  color: var(--sub); letter-spacing: .08em; transition: color .2s;
  white-space: nowrap; flex-shrink: 0;
}
body.state-success .user-meta,
body.state-fail    .user-meta,
body.state-waiting .user-meta,
body.state-offline .user-meta,
body.state-loading .user-meta { color: rgba(255,255,255,.75); }

/* Punch area */
.punch-area {
  display: flex; flex-direction: column; align-items: center;
  gap: 32px;
}
@media (min-width: 768px) {
  .punch-area { gap: 40px; }
}
.punch-wrapper { position: relative; width: var(--btn-size); height: var(--btn-size); }
.punch-ring {
  position: absolute; inset: -12px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.1); pointer-events: none; transition: border-color .2s;
}
body.state-success .punch-ring,
body.state-fail    .punch-ring,
body.state-waiting .punch-ring,
body.state-offline .punch-ring,
body.state-loading .punch-ring { border-color: rgba(255,255,255,.6); }
.punch-btn {
  width: 100%; height: 100%; border-radius: 50%; border: none;
  background: var(--punch); color: var(--text);
  font-family: 'Share Tech Mono', monospace; font-size: 1.3rem;
  letter-spacing: .12em; text-transform: uppercase; cursor: pointer;
  position: relative; z-index: 1;
  box-shadow: 0 4px 20px rgba(0,0,0,.09), inset 0 1px 0 rgba(255,255,255,.65);
  transition: background .1s, transform .08s, color .2s;
  -webkit-user-select: none; user-select: none;
}
@media (min-width: 768px) {
  .punch-btn { font-size: 1.6rem; }
}
.punch-btn:active:not(:disabled) { transform: scale(.94); }
.punch-btn:disabled { cursor: not-allowed; }
body.state-success .punch-btn { background: var(--green-dk); }
body.state-fail    .punch-btn { background: var(--red-dk); }
body.state-waiting .punch-btn { background: var(--orange-dk); }
body.state-offline .punch-btn { background: var(--red-dk); }
body.state-loading .punch-btn { background: var(--blue-dk); }
body.state-loading .punch-btn,
body.state-success .punch-btn,
body.state-fail    .punch-btn,
body.state-waiting .punch-btn,
body.state-offline .punch-btn { color: transparent !important; }

/* Punch label */
.punch-label {
  font-family: 'Share Tech Mono', monospace; font-size: .78rem;
  letter-spacing: .2em; text-transform: uppercase; color: var(--sub);
  transition: color .2s; text-align: center; min-height: 1.2em;
  max-width: 320px;
}
@media (min-width: 768px) {
  .punch-label { font-size: .88rem; }
}
body.state-success .punch-label,
body.state-fail    .punch-label,
body.state-waiting .punch-label,
body.state-offline .punch-label,
body.state-loading .punch-label { color: rgba(255,255,255,.95); }

/* Status icons */
.status-icon {
  position: absolute; inset: -10px; width: auto; height: auto;
  transform: scale(.6); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .25s cubic-bezier(.34,1.56,.64,1); z-index: 2;
}
body.state-success .check-icon   { opacity: 1; transform: scale(1); }
body.state-fail    .fail-icon    { opacity: 1; transform: scale(1); }
body.state-waiting .wait-icon    { opacity: 1; transform: scale(1); }
body.state-loading .queued-icon  { opacity: 1; transform: scale(1); }
body.state-offline .offline-icon { opacity: 1; transform: scale(1); }

.check-circle  { stroke-dasharray: 150; stroke-dashoffset: 150; }
.check-tick    { stroke-dasharray: 40;  stroke-dashoffset: 40; }
.fail-circle   { stroke-dasharray: 150; stroke-dashoffset: 150; }
.fail-x1, .fail-x2 { stroke-dasharray: 30; stroke-dashoffset: 30; }

body.state-success .check-circle { animation: drawCircle .3s ease forwards; }
body.state-success .check-tick   { animation: drawTick .22s ease .28s forwards; }
body.state-fail    .fail-circle  { animation: drawCircle .3s ease forwards; }
body.state-fail    .fail-x1      { animation: drawTick .2s ease .28s forwards; }
body.state-fail    .fail-x2      { animation: drawTick .2s ease .42s forwards; }

@keyframes drawCircle { to { stroke-dashoffset: 0; } }
@keyframes drawTick   { to { stroke-dashoffset: 0; } }

/* Queued icon animation — subtle pulse on the hourglass */
.queued-icon .hg-sand-top,
.queued-icon .hg-sand-bot {
  animation: sandDrop 1.6s ease-in-out infinite;
  transform-origin: center;
}
.queued-icon .hg-sand-bot { animation-delay: .2s; }
@keyframes sandDrop {
  0%, 100% { opacity: .6; transform: scaleY(1); }
  50%      { opacity: 1;  transform: scaleY(1.05); }
}

/* Loading ring: arc sits exactly on the button border edge.
   SVG overflow:visible so the stroke (half outside r=50) is not clipped.
   stroke-width matches check-circle (2.5) for visual consistency. */
.punch-ring-loader {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  opacity: 0; transition: opacity .15s;
  z-index: 3; pointer-events: none;
}
body.state-loading .punch-ring-loader { opacity: 1; }
.punch-ring-loader svg {
  width: 100%; height: 100%;
  overflow: visible;
  animation: ringSpin 1.4s linear infinite;
}
.punch-ring-loader circle {
  fill: none;
  stroke: rgba(255,255,255,.95);
  stroke-width: 5.4;
  stroke-linecap: round;
  stroke-dasharray: 80 220;
}
@keyframes ringSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Today's punch log wrapper inside log-section */
.log-inner {
  width: 100%; max-width: 420px;
  flex: 1;
  display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100dvh - 100px);
}
@media (min-width: 768px) {
  .log-inner { max-width: 560px; gap: 18px; }
  .log-title { font-size: .78rem !important; letter-spacing: .24em !important; }
}
.log-title {
  font-family: 'Share Tech Mono', monospace; font-size: .7rem;
  letter-spacing: .2em; text-transform: uppercase; color: var(--sub);
  text-align: center; transition: color .2s;
  flex-shrink: 0;
}
body.state-success .log-title,
body.state-fail    .log-title,
body.state-waiting .log-title,
body.state-offline .log-title,
body.state-loading .log-title { color: rgba(255,255,255,.6); }

.log-grid {
  display: flex; flex-direction: column; gap: 8px;
  flex: 1;
  width: 100%;
  min-height: 420px;
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  padding: 12px;
  background: rgba(0,0,0,.03);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 4px;
  transition: background .2s, border-color .2s;
  overscroll-behavior: contain;
}
@media (min-width: 768px) {
  .log-grid { gap: 10px; padding: 16px; min-height: 520px; }
}
body.state-success .log-grid,
body.state-fail    .log-grid,
body.state-waiting .log-grid,
body.state-offline .log-grid,
body.state-loading .log-grid {
  background: rgba(0,0,0,.08);
  border-color: rgba(255,255,255,.15);
}
.log-grid::-webkit-scrollbar { width: 6px; }
.log-grid::-webkit-scrollbar-track { background: transparent; }
.log-grid::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.2); border-radius: 3px;
}
body.state-success .log-grid::-webkit-scrollbar-thumb,
body.state-fail    .log-grid::-webkit-scrollbar-thumb,
body.state-waiting .log-grid::-webkit-scrollbar-thumb,
body.state-offline .log-grid::-webkit-scrollbar-thumb,
body.state-loading .log-grid::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.35);
}

.log-row {
  background: var(--bg-card); border-radius: 4px;
  padding: 12px 16px;
  border: 1px solid rgba(0,0,0,.06);
  display: flex; align-items: center; gap: 12px;
  transition: background .2s, border-color .2s;
}
@media (min-width: 768px) {
  .log-row { padding: 14px 18px; gap: 14px; }
  .log-name { font-size: 1rem !important; }
  .log-time { font-size: .8rem !important; }
  .log-type { font-size: .7rem !important; padding: 5px 10px !important; }
}
body.state-success .log-row,
body.state-fail    .log-row,
body.state-waiting .log-row,
body.state-offline .log-row,
body.state-loading .log-row { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.2); }

.log-name {
  font-family: 'Rajdhani', sans-serif; font-weight: 700; font-size: .9rem;
  letter-spacing: .04em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
  transition: color .2s;
}
body.state-success .log-name,
body.state-fail    .log-name,
body.state-waiting .log-name,
body.state-offline .log-name,
body.state-loading .log-name { color: #fff; }

.log-time {
  font-family: 'Share Tech Mono', monospace; font-size: .7rem;
  color: var(--sub); letter-spacing: .04em;
  flex-shrink: 0; white-space: nowrap;
  transition: color .2s;
}
body.state-success .log-time,
body.state-fail    .log-time,
body.state-waiting .log-time,
body.state-offline .log-time,
body.state-loading .log-time { color: rgba(255,255,255,.7); }

.log-type {
  font-family: 'Share Tech Mono', monospace; font-size: .62rem;
  letter-spacing: .1em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 3px;
  white-space: nowrap; flex-shrink: 0;
}
.log-type.t-in  { background: rgba(34,197,94,.2);  color: var(--green-dk); }
.log-type.t-out { background: rgba(59,130,246,.2); color: #1E40AF; }
body.state-success .log-type.t-in,
body.state-fail    .log-type.t-in,
body.state-waiting .log-type.t-in,
body.state-offline .log-type.t-in,
body.state-loading .log-type.t-in  { background: rgba(255,255,255,.25); color: #fff; }
body.state-success .log-type.t-out,
body.state-fail    .log-type.t-out,
body.state-waiting .log-type.t-out,
body.state-offline .log-type.t-out,
body.state-loading .log-type.t-out { background: rgba(255,255,255,.25); color: #fff; }

.log-empty {
  font-family: 'Share Tech Mono', monospace; font-size: .7rem;
  color: var(--sub); letter-spacing: .1em; text-align: center;
  padding: 24px; transition: color .2s;
}
body.state-success .log-empty,
body.state-fail    .log-empty,
body.state-waiting .log-empty,
body.state-offline .log-empty,
body.state-loading .log-empty { color: rgba(255,255,255,.5); }

/* App loader */
#app-loader {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Share Tech Mono', monospace; font-size: .8rem;
  color: var(--sub); letter-spacing: .15em;
  transition: opacity .3s;
  z-index: 100;
}
#app-loader.hidden { opacity: 0; pointer-events: none; }
