* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: #f4f7fc; color: #0b1a33; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; }
.handwriting-header { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px; flex-shrink: 0; min-height: 66px; padding: 10px 28px; background: #fff; border-bottom: 1px solid #e7edf5; }
.handwriting-plan { justify-self: start; display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 8px; font-size: .8rem; font-weight: 500; }
.handwriting-plan strong { font-size: .85rem; font-style: italic; font-weight: 800; }
.handwriting-plan.is-free { color: #16803d; background: #eaf8ef; }
.handwriting-title { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; font-size: 1.325rem; font-weight: 700; line-height: 1.4; }
.handwriting-title-icon { display: grid; place-items: center; width: 36px; height: 36px; color: #006acd; font-size: 1.5rem; }
.handwriting-title-icon > i { display: flex; align-items: center; justify-content: center; line-height: 1; }
.handwriting-open-link { display: inline-flex; align-items: center; gap: 6px; justify-self: end; color: #69798d; font-size: .9rem; text-decoration: none; white-space: nowrap; }
.handwriting-open-link:hover { color: #006acd; text-decoration: none; }
.handwriting-main { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 24px; width: 100%; padding: 32px 24px 16px; }
.handwriting-wrapper { display: flex; flex: 1 0 auto; align-items: center; justify-content: center; width: 100%; }
.handwriting-card { width: 100%; max-width: 1100px; min-width: 0; padding: 24px 22px 28px; background: #fff; border: 1px solid #e5ebf3; border-radius: 24px; box-shadow: 0 12px 40px rgba(18, 61, 107, .06); }
.handwriting-intro { margin: 0 0 24px; color: #66758a; font-size: .9rem; line-height: 1.7; text-align: center; }
.size-form { margin-bottom: 20px; padding: 16px; border: 1px solid #eef2f8; border-radius: 14px; background: #f8faff; }
.size-fields { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.size-fields > label { display: flex; flex-direction: column; gap: 8px; min-width: 0; color: #4b5a6a; font-size: .8rem; }
.number-wrap { display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid #d2dce9; border-radius: 10px; background: #fff; color: #8895a7; }
.number-wrap input { width: 110px; min-width: 0; min-height: 38px; padding: 6px 0; border: 0; background: transparent; color: #0b1a33; font: inherit; font-variant-numeric: tabular-nums; }
.number-wrap:focus-within { outline: 3px solid #8ec7ff; outline-offset: 2px; }
.number-wrap input:focus { outline: 0; }
.number-wrap:has([aria-invalid="true"]) { border-color: #c43d4b; }
.size-times { align-self: end; padding-bottom: 8px; color: #8895a7; }
.hw-help { margin: 9px 0 0; color: #66758a; font-size: .78rem; line-height: 1.7; overflow-wrap: anywhere; }
.drawing-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 24px; margin-bottom: 16px; font-size: .82rem; }
.color-control, .pen-width, .check-control, .background-controls { display: inline-flex; align-items: center; gap: 8px; }
.color-control input { width: 34px; height: 30px; padding: 2px; border: 1px solid #d2dce9; border-radius: 6px; background: #fff; cursor: pointer; }
.color-control input:disabled { opacity: .4; cursor: default; }
.pen-width { flex: 1; min-width: 200px; }
.pen-width input { width: 100px; min-width: 50px; max-width: 180px; flex: 1; }
.pen-width output { width: 40px; color: #006acd; font-variant-numeric: tabular-nums; }
.background-controls { gap: 18px; }
input[type="range"], input[type="checkbox"] { accent-color: #006acd; cursor: pointer; }
input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }
.board-viewport { display: flex; align-items: center; justify-content: center; min-height: 190px; padding: 14px; border: 1px solid #d2dce9; border-radius: 18px; background: #f8faff; }
.board-surface { position: relative; width: 100%; overflow: hidden; border: 1px dashed #b9cbe0; border-radius: 10px; }
.checker { background-color: #fff; background-image: conic-gradient(#eef2f7 25%, transparent 0 50%, #eef2f7 0 75%, transparent 0); background-size: 20px 20px; }
#handwritingCanvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; }
.board-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #8895a7; font-size: clamp(.7rem, 2vw, 1rem); pointer-events: none; }
.board-caption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 14px; margin-top: 8px; }
.board-caption .hw-help { margin-top: 0; }
.board-info { color: #315d8d; font-size: .78rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.action-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; margin-top: 22px; }
.history-actions, .save-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.save-actions { gap: 14px; }
.check-control { color: #4b5a6a; font-size: .8rem; cursor: pointer; }
.hw-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid #e0e7f0; border-radius: 10px; background: #f4f7fc; color: #4b5a6a; font: inherit; font-size: .82rem; font-weight: 500; text-decoration: none; cursor: pointer; line-height: 1.5; }
.hw-btn:hover { color: #0b1a33; background: #eaf0f8; text-decoration: none; }
.hw-btn.primary { color: #fff; background: #006acd; border-color: #006acd; box-shadow: 0 4px 14px rgba(0, 106, 205, .15); }
.hw-btn.primary:hover { color: #fff; background: #0059b3; }
.hw-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.hw-status { min-height: 22px; margin: 14px 0 0; color: #16803d; font-size: .82rem; line-height: 1.7; overflow-wrap: anywhere; }
.hw-status.is-error { color: #c43d4b; }
.save-result { display: flex; align-items: center; gap: 18px; padding: 16px; margin-top: 12px; border: 1px solid #d8ebdf; border-radius: 14px; background: #f4fbf6; }
.saved-preview { display: flex; align-items: center; justify-content: center; width: 180px; height: 100px; flex-shrink: 0; overflow: hidden; border: 1px solid #e5ebf3; border-radius: 8px; }
.saved-preview img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.save-result > div:last-child { min-width: 0; }
.save-result strong { font-size: .9rem; }
.save-result .hw-btn { margin-top: 10px; }
.handwriting-tips { flex-shrink: 0; width: 100%; max-width: 1100px; margin-top: auto; padding: 18px 16px 0; border-top: 1px solid #eef2f8; color: #66758a; font-size: .9rem; line-height: 1.8; text-align: center; }
.handwriting-tips p { margin: 0; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid #8ec7ff; outline-offset: 3px; }
@media (max-width: 767.98px) {
    .handwriting-header { padding: 8px 16px; gap: 10px; }
    .handwriting-plan { padding: 5px 8px; font-size: .72rem; }
    .handwriting-title { gap: 7px; font-size: 1.175rem; }
    .handwriting-title-icon { width: 32px; height: 32px; font-size: 1.3rem; }
    .handwriting-open-link { font-size: .8rem; }
    .handwriting-main { padding: 24px 16px 16px; gap: 20px; }
    .handwriting-card { padding: 18px 16px 22px; border-radius: 22px; }
    .drawing-toolbar { gap: 14px 18px; }
    .pen-width { min-width: 180px; }
    .board-viewport { padding: 8px; }
}
@media (max-width: 575.98px) {
    .handwriting-header { grid-template-columns: minmax(0, 1fr) auto; }
    .handwriting-title { grid-column: 1 / -1; grid-row: 1; }
    .handwriting-plan { grid-column: 1; grid-row: 2; }
    .handwriting-open-link { grid-column: 2; grid-row: 2; }
    .handwriting-tips { padding: 18px 12px 0; font-size: .8rem; }
    .size-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; }
    .number-wrap { padding: 0 6px; gap: 4px; }
    .number-wrap input { width: 100%; }
    #applySize { grid-column: 1 / -1; }
    .size-form { padding: 12px; }
    .drawing-toolbar > .pen-width { order: 3; width: 100%; }
    .background-controls { margin-left: auto; gap: 8px; }
    .color-control, .check-control { font-size: .75rem; }
    .action-row > div, .save-actions > button { width: 100%; }
    .history-actions .hw-btn { flex: 1; padding: 8px; }
    .save-result { flex-direction: column; align-items: stretch; }
    .saved-preview { width: 100%; height: 120px; }
}
@media (max-width: 380px) { .background-controls { margin-left: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
